.md →
HoverSlider API#
HoverSlider treats hovering as an input channel of its own: hover_value follows
the pointer while value stays parked where you last clicked, so a cell can show
you what a setting would do before you commit to it. Pass start/stop/step for
a linear range or steps for a list of discrete values, and use
sync_throttle_ms to cap how often the hover stream reruns downstream cells.
See also: PlaySlider for stepping through a range on a timer, CircularSlider for the same range laid out on a dial, and TangleSlider for a draggable number that lives inside a sentence.
Bases: AnyWidget
Horizontal slider that reports both a committed value and a live hover value.
Hovering the track is an input channel of its own: hover_value follows the
pointer while value stays parked where you last clicked. That lets a
notebook preview a result before you commit to it. Click (or drag the puck) to
move value; when the pointer leaves the track hover_value falls back to
value, so it is never None.
Mirrors mo.ui.slider semantics: pass start/stop/step for a linear
range, or steps for a list of discrete values (the two are mutually
exclusive). Numeric types are preserved -- steps=[1, 2, 3] hands back an
int, steps=[1, 2.5, 4] hands back floats.
Note
Hover fires a lot. Because mo.ui.anywidget reruns dependent cells on
every synced trait change, sync_throttle_ms is the knob that decides how
hard this widget hits your notebook: the default of 100ms caps it at roughly
10 reruns per second while the pointer sweeps. Raise it if downstream cells
are expensive; set it to 0 to sync every single pointer move.
Examples:
import marimo as mo
from wigglystuff import HoverSlider
slider = mo.ui.anywidget(HoverSlider(start=0, stop=100, step=1, value=42))
slider
# `hover_value` previews, `value` is what the user actually committed.
mo.md(f"previewing {slider.value['hover_value']}, committed {slider.value['value']}")
Create a HoverSlider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Optional[float]
|
Lower bound of the range. Defaults to |
None
|
stop
|
Optional[float]
|
Upper bound of the range. Defaults to |
None
|
step
|
Optional[float]
|
Snap increment (must be > 0). Defaults to |
None
|
steps
|
Optional[Sequence[float]]
|
List of discrete values to snap to, laid out evenly across the
track regardless of spacing. Mutually exclusive with
|
None
|
value
|
Optional[float]
|
Initial committed value; defaults to |
None
|
sync_throttle_ms
|
int
|
Cap on how often hover/drag updates reach Python, in
milliseconds. |
100
|
show_value
|
bool
|
Render the committed and hovered values as text below the track. |
True
|
label
|
str
|
Optional text label shown above the track. Empty string hides it. |
''
|
color
|
str
|
Optional CSS color (e.g. |
''
|
width
|
int
|
Widget width in pixels. |
400
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in wigglystuff/hover_slider.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
value |
int \| float |
Committed value. Moves on click, drag, and arrow keys — never on plain hover. |
hover_value |
int \| float |
Value under the pointer. Falls back to value when the pointer leaves, so it is never None. |
hovering |
bool |
Whether the pointer is on the track, i.e. whether hover_value is live. |
start |
int \| float |
Lower bound. In steps mode this is steps[0]. |
stop |
int \| float |
Upper bound. In steps mode this is steps[-1]. |
step |
int \| float \| None |
Snap increment. None in steps mode. |
steps |
list[int \| float] |
Discrete values, laid out evenly across the track. Empty means linear mode. |
sync_throttle_ms |
int |
Cap on how often hover updates reach Python. 0 syncs every pointer move. |
show_value |
bool |
Render the committed and hovered values below the track. |
label |
str |
Text above the track. Empty string hides it. |
color |
str |
CSS color for the fill, puck border, and hover marker. Empty uses the theme default. |
width |
int |
Widget width in pixels. |