NumberInput
The NumberInput widget displays a numeric input field that lets users type a number. It is useful for setting parameters like thresholds, limits, counts, or any value that should be a number.
Live Demo
Section titled “Live Demo”You can try the NumberInput widget directly in this interactive example:
To create a NumberInput widget, provide a label.
You can optionally set value, min, max, and step.
Basic Example
Section titled “Basic Example”Code
import mercury as mr
n = mr.NumberInput( label="Enter number", min=0, max=100, step=1)To get the current value:
n.valueDefault Value
Section titled “Default Value”If value is not provided (or is None), the widget defaults to min.
Code
n = mr.NumberInput( label="Rows", min=10, max=100)
n.valueOutput
10Range and Clamping
Section titled “Range and Clamping”The value is always kept within [min, max].
- If
min > max, the values are swapped (and a warning is shown). - If
valueis outside the range, it is clamped to the nearest valid value.
Code
n = mr.NumberInput( label="Probability", value=2.0, min=0.0, max=1.0, step=0.1)
n.valueOutput
1.0Layout
Section titled “Layout”Use the position argument to control where the widget is displayed.
The default is position="sidebar".
Available positions:
"sidebar"— displayed in the left sidebar (default)"inline"— displayed in the main notebook output"bottom"— displayed after all notebook cells
Code
mr.NumberInput( label="Threshold", value=0.5, min=0.0, max=1.0, step=0.05, position="inline")NumberInput Props
Section titled “NumberInput Props”type: string
Text displayed above the input.
The default is "Enter number".
type: float | None
Initial numeric value.
- If
Noneor omitted, it defaults tomin. - If outside
[min, max], it is clamped during initialization.
At runtime, .value is always a number.
type: float
Minimum allowed value.
The default is 0.
type: float
Maximum allowed value.
The default is 100.
type: float
Step used by the browser numeric input.
The default is 1.
position
Section titled “position”type: "sidebar" | "inline" | "bottom"
Controls where the widget is rendered:
- sidebar — in the sidebar (default)
- inline — directly in the notebook cell output
- bottom — after all notebook cells
disabled
Section titled “disabled”type: bool
If True, the input is visible but cannot be changed.
The default is False.
hidden
Section titled “hidden”type: bool
If True, the widget exists in the UI state but is not rendered.
The default is False.
type: string
Unique identifier used to distinguish widgets with identical arguments.
- The widget value is always numeric and available via
.value. - The value is clamped to the
[min, max]range. - If you need integer-only input, set
step=1and use integermin/max.