Skip to content

components

InputNumeric(label, value=0, on_value=None, disabled=False, optional=False, continuous_update=False, clearable=False, classes=[], style=None, autofocus=False)

Numeric input (float | integers).

Basic example:

import solara

int_value = solara.reactive(42)
continuous_update = solara.reactive(True)

@solara.component
def Page():
    solara.Checkbox(label="Continuous update", value=continuous_update)
    solara.InputInt("Enter an integer number", value=int_value, continuous_update=continuous_update.value)
    with solara.Row():
        solara.Button("Clear", on_click=lambda: int_value.set(42))
    solara.Markdown(f"**You entered**: {int_value.value}")

Arguments

  • label: Label to display next to the slider.
  • value: The currently entered value.
  • on_value: Callback to call when the value changes.
  • disabled: Whether the input is disabled.
  • optional: Whether the value can be None.
  • continuous_update: Whether to call the on_value callback on every change or only when the input loses focus or the enter key is pressed.
  • clearable: Whether the input can be cleared.
  • classes: List of CSS classes to apply to the input.
  • style: CSS style to apply to the input.
  • autofocus: Determines if a component is to be autofocused or not (Default is False). Autofocus will occur either during page load, or when the component becomes visible (for example, dialog being opened). Only one component per page should have autofocus on each such event.
Source code in hdxms_datasets/web/components.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@solara.component
def InputNumeric(
    label: str,
    value: Union[None, num, solara.Reactive[num], solara.Reactive[Optional[num]]] = 0,
    on_value: Union[None, Callable[[Optional[num]], None], Callable[[num], None]] = None,
    disabled: bool = False,
    optional: bool = False,
    continuous_update: bool = False,
    clearable: bool = False,
    classes: list[str] = [],
    style: Optional[Union[str, dict[str, str]]] = None,
    autofocus: bool = False,
):
    """Numeric input (float | integers).

    Basic example:

    ```solara
    import solara

    int_value = solara.reactive(42)
    continuous_update = solara.reactive(True)

    @solara.component
    def Page():
        solara.Checkbox(label="Continuous update", value=continuous_update)
        solara.InputInt("Enter an integer number", value=int_value, continuous_update=continuous_update.value)
        with solara.Row():
            solara.Button("Clear", on_click=lambda: int_value.set(42))
        solara.Markdown(f"**You entered**: {int_value.value}")
    ```

    ## Arguments

    * `label`: Label to display next to the slider.
    * `value`: The currently entered value.
    * `on_value`: Callback to call when the value changes.
    * `disabled`: Whether the input is disabled.
    * `optional`: Whether the value can be None.
    * `continuous_update`: Whether to call the `on_value` callback on every change or only when the input loses focus or the enter key is pressed.
    * `clearable`: Whether the input can be cleared.
    * `classes`: List of CSS classes to apply to the input.
    * `style`: CSS style to apply to the input.
    * `autofocus`: Determines if a component is to be autofocused or not (Default is False). Autofocus will occur either during page load, or when the component becomes visible (for example, dialog being opened). Only one component per page should have autofocus on each such event.
    """

    def str_to_num(value: Optional[str]):
        if value:
            try:
                return int(value)
            except ValueError:
                try:
                    return float(value)
                except ValueError:
                    raise ValueError(f"Cannot convert {value} to a number")
        else:
            if optional:
                return None
            else:
                raise ValueError("Value cannot be empty")

    return _InputNumeric(
        str_to_num,
        label=label,
        value=value,
        on_value=on_value,
        disabled=disabled,
        continuous_update=continuous_update,
        clearable=clearable,
        classes=classes,
        style=style,
        autofocus=autofocus,
    )