| Parameters |
| |
A short label explaining to the user what this slider is for.
The label can optionally contain GitHub-flavored Markdown of the
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
and Images. Images display like icons, with a max height equal to
the font height.
Unsupported Markdown elements are unwrapped so only their children
(text contents) render. Common block-level Markdown (headings,
lists, blockquotes) is automatically escaped and displays as
literal text in labels.
See the body parameter of st.markdown for additional,
supported Markdown directives.
For accessibility reasons, you should never set an empty label, but
you can hide it with label_visibility if needed. In the future,
we may disallow empty labels by raising an exception.
|
min_value
(a supported type or None)
|
The minimum permitted value.
If this is None (default), the minimum value depends on the
type as follows:
- integer: 0
- float: 0.0
- date or datetime: value - timedelta(days=14)
- time: time.min
|
max_value
(a supported type or None)
|
The maximum permitted value.
If this is None (default), the maximum value depends on the
type as follows:
- integer: 100
- float: 1.0
- date or datetime: value + timedelta(days=14)
- time: time.max
|
value
(a supported type or a tuple/list of supported types or None)
|
The value of the slider when it first renders. If a tuple/list
of two values is passed here, then a range slider with those lower
and upper bounds is rendered. For example, if set to (1, 10) the
slider will have a selectable range between 1 and 10.
This defaults to min_value. If the type is not otherwise
specified in any of the numeric parameters, the widget will have an
integer value.
|
step
(int, float, timedelta, or None)
|
The stepping interval.
Defaults to 1 if the value is an int, 0.01 if a float,
timedelta(days=1) if a date/datetime, timedelta(minutes=15) if a time
(or if max_value - min_value < 1 day)
|
| |
A printf-style format string or a predefined format name controlling
how the interface should display values. This does not impact the
return value.
For integers and floats, you can use a printf-style format string
or one of the following predefined formats:
- "plain": Show the full number without formatting (e.g. 1234.567).
- "localized": Show the number in the user's locale format (e.g. 1,234.567).
- "percent": Show as a percentage (e.g. 50% from 0.5).
- "dollar": Show as US dollars (e.g. $1,234.57).
- "euro": Show as euros (e.g. €1,234.57).
- "yen": Show as Japanese yen (e.g. ¥1,235).
- "compact": Show in compact notation (e.g. 1.2K).
- "scientific": Show in scientific notation (e.g. 1.235E3).
- "engineering": Show in engineering notation (e.g. 1.235E3).
- "accounting": Show in accounting format with parentheses for negatives.
- "bytes": Show in byte units (e.g. 1.2KB).
For information about printf-style format strings, see
sprintf.js.
For example, format="%0.1f" adjusts the displayed decimal
precision to only show one digit after the decimal. Use , for
thousand separators (e.g. "%,d" yields "1,234").
For datetimes, dates, and times, you can use a momentJS format string
or one of the following predefined formats:
- "localized": Show in the user's locale format.
- "distance": Show as relative time (e.g. "2 hours ago").
- "calendar": Show as calendar time (e.g. "Tomorrow 12:00").
Works best with datetime values. For date-only values, displays
relative day names (e.g. "Yesterday"). For time-only values,
this format may produce unexpected results.
- "iso8601": Show in ISO 8601 format.
For information about momentJS format strings, see
momentJS.
For example, format="ddd ha" adjusts the displayed datetime to
show the day of the week and the hour ("Tue 8pm").
|
| |
An optional string or integer to use as the unique key for
the widget. If this is None (default), a key will be
generated for the widget based on the values of the other
parameters. No two widgets may have the same key. Assigning
a key stabilizes the widget's identity and preserves its
state across reruns even when other parameters change.
Note
Changing min_value, max_value, or step resets
the widget even when a key is provided, because those
parameters constrain valid values.
A key lets you read or update the widget's value via
st.session_state[key]. For more details, see Widget
behavior.
Additionally, if key is provided, it will be used as a
CSS class name prefixed with st-key-.
|
| |
A tooltip that gets displayed next to the widget label. Streamlit
only displays the tooltip when label_visibility="visible". If
this is None (default), no tooltip is displayed.
The tooltip can optionally contain GitHub-flavored Markdown,
including the Markdown directives described in the body
parameter of st.markdown.
|
on_change
(callable, "rerun", "ignore", or None)
|
How the slider should respond to value changes. This controls
whether or not Streamlit reruns the app when the user interacts
with the slider. on_change can be one of the following:
- "rerun" (default): Streamlit will rerun the app when the
user changes the slider value.
- "ignore": Streamlit will not rerun the app when the user
changes the slider value. The slider still updates in the UI.
The new value is available on the next rerun triggered by
something else, such as another widget interaction. Ignored
changes are held in the browser and are lost if the page is
refreshed before that rerun, unless bind="query-params"
is set (see bind).
- A callable: Streamlit will rerun the app and execute the
callable as a callback function before the rest of the app.
- None: This is the same as on_change="rerun". This value
exists for backwards compatibility and shouldn't be used.
|
| |
An optional list or tuple of args to pass to the callback.
|
| |
An optional dict of kwargs to pass to the callback.
|
| |
An optional boolean that disables the slider if set to True.
The default is False.
|
label_visibility
("visible", "hidden", or "collapsed")
|
The visibility of the label. The default is "visible". If this
is "hidden", Streamlit displays an empty spacer instead of the
label, which can help keep the widget aligned with other widgets.
If this is "collapsed", Streamlit displays no label or spacer.
|
| |
The width of the slider widget. This can be one of the
following:
- "stretch" (default): The width of the widget matches the
width of the parent container.
- An integer specifying the width in pixels: The widget has a
fixed width. If the specified width is greater than the width of
the parent container, the width of the widget matches the width
of the parent container.
|
bind
("query-params" or None)
|
Binding mode for syncing the widget's value with a URL query
parameter. If this is None (default), the widget's value
is not synced to the URL. When this is set to
"query-params", changes to the widget update the URL, and
the widget can be initialized or updated through a query
parameter in the URL. This requires key to be set. The
key is used as the query parameter name.
When the widget's value equals its default, the query
parameter is removed from the URL to keep it clean. A bound
query parameter can't be set or deleted through
st.query_params; it can only be programmatically changed
through st.session_state.
Invalid query parameter values are ignored and removed
from the URL. Range sliders use repeated parameters (e.g.,
?price=10&price=90).
When on_change="ignore", slider interactions still update
the URL immediately, the same as widgets inside a form. Python
receives the new value on the next rerun. A page load or share
uses the updated URL value.
|
persist_state
("page", "session", or None)
|
How long to preserve the widget's value when it isn't rendered.
If this is None (default), the value is lost when the widget
stops being rendered or the user switches pages. If this is
"page", the value is preserved only while the user stays on the
page where the widget is defined (for example, while the widget is
conditionally hidden); it is discarded on a page switch and is not
restored if the user returns to the page. If this is "session",
the value is preserved for the entire session, including across
page switches, so it returns when the user navigates back. This
requires key to be set. If bind="query-params" is also set,
the binding takes precedence: the value is stored in the URL, so it
persists across page switches regardless of the persist_state
scope.
|