shiny.ui.input_selectize#

shiny.ui.input_selectize(id, label, choices, *, selected=None, multiple=False, width=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?

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

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.

See also

input_select

Example

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

app_ui = ui.page_fluid(
    ui.input_selectize(
        "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"},
        },
        multiple=True,
    ),
    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)