shiny.ui.update_slider#

shiny.ui.update_slider(id, *, label=None, value=None, min=None, max=None, step=None, time_format=None, timezone=None, session=None)#

Change the value of a slider input on the client.

Parameters
  • id (str) – An input id.

  • label (Optional[str]) – An input label.

  • value (Union[~SliderValueArg, Tuple[~SliderValueArg, ~SliderValueArg], None]) – A new value.

  • min (Optional[~SliderValueArg]) – The minimum allowed value.

  • max (Optional[~SliderValueArg]) – The maximum allowed value.

  • step (Union[float, timedelta, None]) – Specifies the interval between each selectable value on the slider. Either None (the default), which uses a heuristic to determine the step size or a single number. If the values are dates, step is in days; if the values are date-times, step is in seconds.

  • time_format (Optional[str]) – Only used if the slider values are date() or datetime() objects. A time format string, to be passed to the Javascript strftime library. See https://github.com/samsonjs/strftime for more details. For Dates, the default is “%F” (like “2015-07-01”), and for Datetimes, the default is “%F %T” (like “2015-07-01 15:32:10”).

  • timezone (Optional[str]) – Only used if the values are datetime() objects. A string specifying the time zone offset for the displayed times, in the format “+HHMM” or “-HHMM”. If None (the default), times will be displayed in the browser’s time zone. The value “+0000” will result in UTC time.

  • session (Optional[Session]) – A Session instance. If not provided, it is inferred via get_current_session().

Note

The input updater functions send a message to the client, telling it to change the settings of an input object. The messages are collected and sent after all the observers (including outputs) have finished running.

The syntax of these functions is similar to the functions that created the inputs in the first place. For example, input_numeric() and update_numeric() take a similar set of arguments.

Any arguments with None values will be ignored; they will not result in any changes to the input object on the client.

For update_radio_buttons(), update_checkbox_group(), and update_select(), the set of choices can be cleared by using choices=[]. Similarly, for these inputs, the selected item can be cleared by using selected=[].

See also

input_slider

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *

app_ui = ui.page_fluid(
    ui.layout_sidebar(
        ui.panel_sidebar(
            ui.tags.p("The first slider controls the second"),
            ui.input_slider("control", "Controller:", min=0, max=20, value=10, step=1),
            ui.input_slider("receive", "Receiver:", min=0, max=20, value=10, step=1),
        ),
        ui.panel_main(),
    )
)

def server(input: Inputs, output: Outputs, session: Session):
    @reactive.Effect
    def _():
        val = input.control()
        # Control the value, min, max, and step.
        # Step size is 2 when input value is even; 1 when value is odd.
        ui.update_slider(
            "receive", value=val, min=int(val / 2), max=val + 4, step=(val + 1) % 2 + 1
        )


app = App(app_ui, server)
Return type

None