RadioButton¶
Bases: InputElement
_value_type: type
property
¶
Get the RadioButton value type: string str
.
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, options=[], horizontal=False, kwargs)
¶
A single choice represented as a group of exclusive radio buttons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
ID of the element. It must be unique as it is the key used to story data in
Project(), otherwise it will lead to conflicts at runtime in both execution and
Streamlit modes. The key will be transformed into snake case and slugified to avoid
any special character or whitespace. Note that an ID cannot start with |
required |
value |
Optional[Union[str, List[str]]]
|
Radio button initially selected. |
required |
label |
Optional[str]
|
Label to display on top of the field. |
None
|
count |
Optional[Union[int, str]]
|
Specify the number of occurence of the widget. OneCode typically uses it for the
streamlit case. Note that if |
None
|
optional |
Union[bool, str]
|
Specify whether the value may be None. |
False
|
hide_when_disabled |
bool
|
If element is optional, set it to True to hide it from the interface, otherwise it will be shown disabled. |
False
|
options |
List[str]
|
List all possible options available. This list may either be fixed or dynamic
(to a certain extent): in the latter case, use expressions in a similar way as
|
[]
|
horizontal |
bool
|
Set to True to have radio buttons displayed horizontally, otherwise radio buttons will be displayed vertically. |
False
|
**kwargs |
Any
|
Extra user meta-data to attach to the element. Argument names cannot overwrite
existing attributes or methods name such as |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if the |
AttributeError
|
if one the |
Example
Fixed options:
from onecode import radio_button, Mode, Project
Project().mode = Mode.EXECUTE
widget = radio_button(
key="RadioButton",
value="A",
options=["A", "B", "C"]
)
print(widget)
"A"
Dynamic options:
from onecode import csv_reader, radio_button, Mode, Project
Project().mode = Mode.EXECUTE
df = csv_reader("csv", "/path/to/file.csv")
widget = radio_button(
key="Dynamic RadioButton",
value=None,
options='$csv$.columns',
optional=True
)
assert widget is None
_validate(value)
¶
Raises:
Type | Description |
---|---|
ValueError
|
if the choice is not part of possible options. |
streamlit(id)
¶
Returns:
Type | Description |
---|---|
str
|
The Streamlit code for a group of radio buttons ( |