NumberInput¶
Bases: InputElement
_value_type: type
property
¶
Get the NumberInput value type: floating point number float
.
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, min=None, max=None, step=None, kwargs)
¶
A field 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
|
Optionally limit the possible values with a lower bound. |
None
|
max |
float
|
Optionally limit the possible values with an upper bound. |
None
|
step |
float
|
Optionally set a step used when increment/decrement button are used. |
None
|
**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 number_input, Mode, Project
Project().mode = Mode.EXECUTE
widget = number_input(
key="Number Input",
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 number input field ( |