Slider¶
Bases: InputElement
_value_type: type
property
¶
Get the Slider value type: floating point or integer number float|int
.
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, min=0.0, max=1.0, step=0.1, kwargs)
¶
A slider for numerical values.
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[float, List[float]]]
|
Initial numerical value. |
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
|
min |
float
|
Mandatory lower bound, defaults to 0. |
0.0
|
max |
float
|
Mandatory upper bound, defaults to 1. |
1.0
|
step |
float
|
Mandatory step used when incrementing/decrementing the slider, defaults to 0.1. |
0.1
|
**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
from onecode import slider, Mode, Project
Project().mode = Mode.EXECUTE
widget = slider(
key="Slider",
value=5.1,
min=5,
max=6
)
print(widget)
5.1
_validate(value)
¶
Raises:
Type | Description |
---|---|
ValueError
|
if the value is out of bound (min/max) or if the minimum is greather than the maximum. |
streamlit(id)
¶
Returns:
Type | Description |
---|---|
str
|
The Streamlit code for a slider ( |