Slider - marimo (original) (raw)

`` marimo.ui.slider

[](#%5F%5Fcodelineno-0-1)slider( [](#%5F%5Fcodelineno-0-2) start: Numeric | None = None, [](#%5F%5Fcodelineno-0-3) stop: Numeric | None = None, [](#%5F%5Fcodelineno-0-4) step: Numeric | None = None, [](#%5F%5Fcodelineno-0-5) value: Numeric | None = None, [](#%5F%5Fcodelineno-0-6) debounce: bool = False, [](#%5F%5Fcodelineno-0-7) disabled: bool = False, [](#%5F%5Fcodelineno-0-8) orientation: Literal[ [](#%5F%5Fcodelineno-0-9) "horizontal", "vertical" [](#%5F%5Fcodelineno-0-10) ] = "horizontal", [](#%5F%5Fcodelineno-0-11) show_value: bool = False, [](#%5F%5Fcodelineno-0-12) include_input: bool = False, [](#%5F%5Fcodelineno-0-13) steps: Sequence[Numeric] | None = None, [](#%5F%5Fcodelineno-0-14) *, [](#%5F%5Fcodelineno-0-15) label: str = "", [](#%5F%5Fcodelineno-0-16) on_change: Callable[[Optional[Numeric]], None] [](#%5F%5Fcodelineno-0-17) | None = None, [](#%5F%5Fcodelineno-0-18) full_width: bool = False [](#%5F%5Fcodelineno-0-19))

Bases: UIElement[Numeric, Numeric]

A numeric slider over an interval.

Example

[](#%5F%5Fcodelineno-0-1)slider = mo.ui.slider(start=1, stop=10, step=2)

Or from a dataframe series:

[](#%5F%5Fcodelineno-1-1)slider = mo.ui.slider.from_series(df["column_name"])

Or using numpy arrays:

[](#%5F%5Fcodelineno-2-1)import numpy as np [](#%5F%5Fcodelineno-2-2) [](#%5F%5Fcodelineno-2-3)# linear steps [](#%5F%5Fcodelineno-2-4)steps = np.array([1, 2, 3, 4, 5]) [](#%5F%5Fcodelineno-2-5)slider = mo.ui.slider(steps=steps) [](#%5F%5Fcodelineno-2-6)# log steps [](#%5F%5Fcodelineno-2-7)log_slider = mo.ui.slider(steps=np.logspace(0, 3, 4)) [](#%5F%5Fcodelineno-2-8)# power steps [](#%5F%5Fcodelineno-2-9)power_slider = mo.ui.slider(steps=np.power([1, 2, 3], 2))

ATTRIBUTE DESCRIPTION
value The current numeric value of the slider. TYPE: Numeric
start The minimum value of the interval. TYPE: Numeric
stop The maximum value of the interval. TYPE: Numeric
step The slider increment. TYPE: Numeric | None
steps List of steps. TYPE: Sequence[Numeric] | None
PARAMETER DESCRIPTION
start The minimum value of the interval. TYPE: Numeric | None DEFAULT: None
stop The maximum value of the interval. TYPE: Numeric | None DEFAULT: None
step The slider increment. TYPE: Numeric | None DEFAULT: None
value Default value. TYPE: Numeric | None DEFAULT: None
debounce Whether to debounce the slider to only send the value on mouse-up or drag-end. Defaults to False. TYPE: bool DEFAULT: False
disabled Whether the slider is disabled. Defaults to False. TYPE: bool DEFAULT: False
orientation The orientation of the slider, either "horizontal" or "vertical". Defaults to "horizontal". TYPE: Literal['horizontal', 'vertical'] DEFAULT: 'horizontal'
show_value Whether to display the current value of the slider. Defaults to False. TYPE: bool DEFAULT: False
include_input Whether to display an editable input with the current value of the slider. Defaults to False. TYPE: bool DEFAULT: False
steps List of steps to customize the slider, mutually exclusive with start, stop, and step. TYPE: Sequence[Numeric] | None DEFAULT: None
label Markdown label for the element. Defaults to an empty string. TYPE: str DEFAULT: ''
on_change Optional callback to run when this element's value changes. TYPE: Callable[[Optional[Numeric]], None] | None DEFAULT: None
full_width Whether the input should take up the full width of its container. Defaults to False. TYPE: bool DEFAULT: False
RAISES DESCRIPTION
ValueError If steps is provided along with start, stop, or step.
ValueError If neither steps nor both start and stop are provided.
ValueError If stop is less than start.
ValueError If value is out of bounds.
TypeError If steps is not a sequence of numbers.
METHOD DESCRIPTION
from_series DataFrameSeries, **kwargs: Any) -> slider: Create a slider from a dataframe series.

`` start instance-attribute

`` step instance-attribute

`` steps instance-attribute

[](#%5F%5Fcodelineno-0-1)steps: Sequence[Numeric] | None

`` stop instance-attribute

`` text property

A string of HTML representing this element.

`` value property writable

The element's current value.

`` batch

[](#%5F%5Fcodelineno-0-1)batch(**elements: UIElement[JSONType, object]) -> [batch](../batch/#marimo.ui.batch " marimo.ui.batch (marimo._plugins.ui._impl.batch.batch)")

Convert an HTML object with templated text into a UI element.

This method lets you create custom UI elements that are represented by arbitrary HTML.

Example

[](#%5F%5Fcodelineno-0-1)user_info = mo.md( [](#%5F%5Fcodelineno-0-2) ''' [](#%5F%5Fcodelineno-0-3) - What's your name?: {name} [](#%5F%5Fcodelineno-0-4) - When were you born?: {birthday} [](#%5F%5Fcodelineno-0-5) ''' [](#%5F%5Fcodelineno-0-6)).batch(name=mo.ui.text(), birthday=mo.ui.date())

In this example, user_info is a UI Element whose output is markdown and whose value is a dict with keys 'name' and 'birthday' (and values equal to the values of their corresponding elements).

PARAMETER DESCRIPTION
elements the UI elements to interpolate into the HTML template. TYPE: UIElement[JSONType, object] DEFAULT: {}

`` callout

`callout( kind: Literal[ "neutral", "danger", "warn", "success", "info" ] = "neutral" ) -> [Html](../../html/#marimo.Html " marimo.Html

  dataclass

(marimo._output.hypertext.Html)") `

Create a callout containing this HTML element.

A callout wraps your HTML element in a raised box, emphasizing its importance. You can style the callout for different situations with thekind argument.

Examples:

[](#%5F%5Fcodelineno-0-1)mo.md("Hooray, you did it!").callout(kind="success")

[](#%5F%5Fcodelineno-1-1)mo.md("It's dangerous to go alone!").callout(kind="warn")

`` center

Center an item.

Example

[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").center()

RETURNS DESCRIPTION
Html An Html object.

`` form

[](#%5F%5Fcodelineno-0-1)form( [](#%5F%5Fcodelineno-0-2) label: str = "", [](#%5F%5Fcodelineno-0-3) *, [](#%5F%5Fcodelineno-0-4) bordered: bool = True, [](#%5F%5Fcodelineno-0-5) loading: bool = False, [](#%5F%5Fcodelineno-0-6) submit_button_label: str = "Submit", [](#%5F%5Fcodelineno-0-7) submit_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-8) submit_button_disabled: bool = False, [](#%5F%5Fcodelineno-0-9) clear_on_submit: bool = False, [](#%5F%5Fcodelineno-0-10) show_clear_button: bool = False, [](#%5F%5Fcodelineno-0-11) clear_button_label: str = "Clear", [](#%5F%5Fcodelineno-0-12) clear_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-13) validate: Callable[[Optional[JSONType]], str | None] [](#%5F%5Fcodelineno-0-14) | None = None, [](#%5F%5Fcodelineno-0-15) on_change: Callable[[Optional[T]], None] | None = None [](#%5F%5Fcodelineno-0-16)) -> [form](../form/#marimo.ui.form " marimo.ui.form (marimo._plugins.ui._impl.input.form)")[S, T]

Create a submittable form out of this UIElement.

Creates a form that gates submission of a UIElement's value until a submit button is clicked. The form's value is the value of the underlying element from the last submission.

Examples:

Convert any UIElement into a form:

[](#%5F%5Fcodelineno-0-1)prompt = mo.ui.text_area().form()

Combine with HTML.batch to create a form made out of multiple UIElements:

[](#%5F%5Fcodelineno-1-1)form = ( [](#%5F%5Fcodelineno-1-2) mo.ui.md( [](#%5F%5Fcodelineno-1-3) ''' [](#%5F%5Fcodelineno-1-4) **Enter your prompt.** [](#%5F%5Fcodelineno-1-5) [](#%5F%5Fcodelineno-1-6) {prompt} [](#%5F%5Fcodelineno-1-7) [](#%5F%5Fcodelineno-1-8) **Choose a random seed.** [](#%5F%5Fcodelineno-1-9) [](#%5F%5Fcodelineno-1-10) {seed} [](#%5F%5Fcodelineno-1-11) ''' [](#%5F%5Fcodelineno-1-12) ) [](#%5F%5Fcodelineno-1-13) .batch( [](#%5F%5Fcodelineno-1-14) prompt=mo.ui.text_area(), [](#%5F%5Fcodelineno-1-15) seed=mo.ui.number(), [](#%5F%5Fcodelineno-1-16) ) [](#%5F%5Fcodelineno-1-17) .form() [](#%5F%5Fcodelineno-1-18))

PARAMETER DESCRIPTION
label A text label for the form. TYPE: str DEFAULT: ''
bordered Whether the form should have a border. TYPE: bool DEFAULT: True
loading Whether the form should be in a loading state. TYPE: bool DEFAULT: False
submit_button_label The label of the submit button. TYPE: str DEFAULT: 'Submit'
submit_button_tooltip The tooltip of the submit button. TYPE: str | None DEFAULT: None
submit_button_disabled Whether the submit button should be disabled. TYPE: bool DEFAULT: False
clear_on_submit Whether the form should clear its contents after submitting. TYPE: bool DEFAULT: False
show_clear_button Whether the form should show a clear button. TYPE: bool DEFAULT: False
clear_button_label The label of the clear button. TYPE: str DEFAULT: 'Clear'
clear_button_tooltip The tooltip of the clear button. TYPE: str | None DEFAULT: None
validate A function that takes the form's value and returns an error message if invalid, or None if valid. TYPE: Callable[[Optional[JSONType]], str | None] None DEFAULT: None
on_change Optional callback to run when this element's value changes. Defaults to None. TYPE: Callable[[Optional[T]], None] | None DEFAULT: None

`` from_args classmethod

[](#%5F%5Fcodelineno-0-1)from_args( [](#%5F%5Fcodelineno-0-2) data: dict[str, int], [](#%5F%5Fcodelineno-0-3) args: InitializationArgs[S, T], [](#%5F%5Fcodelineno-0-4) memo: dict[int, Any] | None = None, [](#%5F%5Fcodelineno-0-5) basis: UIElement[S, T] | None = None, [](#%5F%5Fcodelineno-0-6)) -> UIElement[S, T]

`` from_series staticmethod

[](#%5F%5Fcodelineno-0-1)from_series( [](#%5F%5Fcodelineno-0-2) series: DataFrameSeries, **kwargs: Any [](#%5F%5Fcodelineno-0-3)) -> [slider](#marimo.ui.slider " marimo.ui.slider (marimo._plugins.ui._impl.input.slider)")

Create a slider from a dataframe series.

`` left

Left-justify.

Example

[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").left()

RETURNS DESCRIPTION
Html An Html object.

`` right

Right-justify.

Example

[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").right()

RETURNS DESCRIPTION
Html An Html object.

`` style

`style( style: dict[str, Any] | None = None, **kwargs: Any ) -> [Html](../../html/#marimo.Html " marimo.Html

  dataclass

(marimo._output.hypertext.Html)") `

Wrap an object in a styled container.

Example

[](#%5F%5Fcodelineno-0-1)mo.md("...").style({"max-height": "300px", "overflow": "auto"}) [](#%5F%5Fcodelineno-0-2)mo.md("...").style(max_height="300px", overflow="auto")

PARAMETER DESCRIPTION
style an optional dict of CSS styles, keyed by property name TYPE: dict[str, Any] | None DEFAULT: None
**kwargs CSS styles as keyword arguments TYPE: Any DEFAULT: {}