Slider
The Slider widget allows users to select a numeric value from a range by dragging a slider handle. It is commonly used for thresholds, limits, percentages, and other numeric parameters in a Mercury App.
Live Demo
Section titled “Live Demo”You can try the Slider widget directly in this interactive example:
To create a Slider widget, you define the numeric range using min and max.
You can optionally provide an initial value.
If no value is provided, the slider defaults to the minimum value.
Basic Example
Section titled “Basic Example”Code
import mercury as mr
threshold = mr.Slider( label="Threshold", min=0, max=10)In this example, the initial value will be:
threshold.value
>>> 0Default Value
Section titled “Default Value”You can explicitly define the initial slider position using the value argument.
Code
threshold = Slider( label="Threshold", min=0, max=10, value=3)If the provided value is outside the [min, max] range, it is automatically clamped.
Layout
Section titled “Layout”Use the position argument to control where the widget is displayed.
The default is position="sidebar", which renders the widget in the left sidebar.
Other available values are:
"inline"— displays the widget directly in the notebook output,"bottom"— displays the widget after all notebook cells.
Code
alpha = Slider( label="Alpha", min=0, max=100, position="inline")Slider Props
Section titled “Slider Props”type: string
Text displayed above the slider.
The default is "Select number".
type: int | None
Initial slider value.
- If
Noneor omitted, the value defaults tomin. - If the value is outside the
[min, max]range, it is clamped automatically.
The value is always an integer.
type: int
Minimum allowed value.
The default is 0.
type: int
Maximum allowed value.
The default is 100.
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 slider is visible but cannot be interacted with.
The default is False.
hidden
Section titled “hidden”type: bool
If True, the widget exists in the UI state but is not rendered.
This is useful for internal state management.
The default is False.
type: string
Unique identifier used to distinguish widgets with identical arguments.
Behavior Notes
Section titled “Behavior Notes”- The slider value is always an integer.
- If no value is provided, the slider starts at
min. - Values outside the
[min, max]range are clamped automatically. - The current value is always available via
.value. - The slider track length remains constant, regardless of how many digits the value has.