ui.input_switch

ui.input_switch(id, label, value=False, *, width=None)

Create a switch that can be used to specify logical values. Similar to input_checkbox, but implies to the user that the change will take effect immediately.

Parameters

id: str

An input id.

label: TagChild

An input label.

value: bool = False

Initial value.

width: Optional[str] = None

The CSS width, e.g. â€˜400px’, or ‘100%’

Returns

Type Description
Tag A UI element.

Notes

Server value

True if checked, False otherwise.

See Also

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
from shiny import App, Inputs, Outputs, Session, render, ui

app_ui = ui.page_fluid(
    ui.input_switch("somevalue", "Some value", False),
    ui.output_text("value"),
)


def server(input: Inputs, output: Outputs, session: Session):
    @render.text
    def value():
        return input.somevalue()


app = App(app_ui, server)