ui.input_select

ui.input_select(
    id
    label
    choices
    *
    selected=None
    multiple=False
    selectize=False
    width=None
    size=None
    remove_button=None
    options=None
)

Create a select list that can be used to choose a single or multiple items from a list of values.

Parameters

id : str

An input id.

label : TagChild

An input label.

choices : SelectChoicesArg

Either a list of choices or a dictionary mapping choice values to labels. Note that if a dictionary is provided, the keys are used as the (input) values so that the dictionary values can hold HTML labels. A dictionary of dictionaries is also supported, and in that case, the top-level keys are treated as <optgroup> labels.

selected : Optional[str | list[str]] = None

The values that should be initially selected, if any.

multiple : bool = False

Is selection of multiple items allowed?

selectize : bool = False

Whether to use selectize.js or not.

width : Optional[str] = None

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

size : Optional[str] = None

Number of items to show in the selection box; a larger number will result in a taller box. Normally, when multiple=False, a select input will be a drop-down list, but when size is set, it will be a box instead.

Returns

: Tag

A UI element.

Notes

Server value

If multiple=False, the server value is a string with the value of the selected item. If multiple=True, the server value is a tuple containing the values of the selected items. When multiple=True and nothing is selected, this value will be None.

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_select(
        "state",
        "Choose a state:",
        {
            "East Coast": {"NY": "New York", "NJ": "New Jersey", "CT": "Connecticut"},
            "West Coast": {"WA": "Washington", "OR": "Oregon", "CA": "California"},
            "Midwest": {"MN": "Minnesota", "WI": "Wisconsin", "IA": "Iowa"},
        },
    ),
    ui.output_text("value"),
)


def server(input: Inputs, output: Outputs, session: Session):
    @render.text
    def value():
        return "You choose: " + str(input.state())


app = App(app_ui, server)