shiny.ui.input_select#

shiny.ui.input_select(id, label, choices, *, selected=None, multiple=False, selectize=False, width=None, size=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 (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An input label.

  • choices (Union[List[str], Tuple[str, …], Mapping[str, Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]], Mapping[str, Mapping[str, Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]]]]) – 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 (Union[str, List[str], None]) – The values that should be initially selected, if any.

  • multiple (bool) – Is selection of multiple items allowed?

  • selectize (bool) – Whether to use selectize.js or not.

  • width (Optional[str]) – The CSS width, e.g. ‘400px’, or ‘100%’

  • size (Optional[str]) – 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.

Return type

A UI element.

Notes

Server value

A list of strings, usually of length 1, with the value of the selected items. When multiple=True and nothing is selected, this value will be None.

Example

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

app_ui = ui.page_fluid(
    ui.input_select(
        "state",
        "Choose a state:",
        {
            "East Coast": {"NY": "NY", "NJ": "NJ", "CT": "CT"},
            "West Coast": {"WA": "WA", "OR": "OR", "CA": "CA"},
            "Midwest": {"MN": "MN", "WI": "WI", "IA": "IA"},
        },
    ),
    ui.output_text("value"),
)

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


app = App(app_ui, server)