MultiChoice#
Download this notebook from GitHub (right-click to download).
import panel as pn
import panel_material_ui as pmui
pn.extension()
The MultiChoice widget allows selecting multiple values from a list of options. It falls into the broad category of multi-value, option-selection widgets that provide a compatible API and include the MultiSelect, CrossSelector, CheckBoxGroup and CheckButtonGroup widgets. The MultiChoice widget provides a much more compact UI than MultiSelect.
Discover more on using widgets to add interactivity to your applications in the how-to guides on interactivity. Alternatively, learn how to set up callbacks and (JS-)links between parameters or how to use them as part of declarative UIs with Param.
Parameters:#
For details on other options for customizing the component see the customization guides.
Core#
bookmarks(list): List of bookmarked options that are rendered first.disabled(boolean): Whether the widget is editabledisabled_options(list): List of options that are disabled.filter_on_search(boolean): Whether to filter or highlight the matching options on search.option_limit(int): Maximum number of options to display at once.options(list or dict): List or dictionary of optionssearch_option_limit(int): Maximum number of options to display at once if search string is entered.max_items(int): Maximum number of options that can be selectedsearchable(boolean): Whether to render a search box.value(list): Currently selected option values
Display#
color(str): The color variant of the input and indicating the selected item(s), which must be one of'default'(white),'primary'(blue),'success'(green),'info'(yellow),'light'(light), or'danger'(red).delete_button(boolean): Whether to display a button to delete a selected optiondropdown_height(int | None): Height of the select dropdown.label(str): The title of the widgetplaceholder(str): String displayed when no selection has been made.solid(boolean): Whether to display widget with solid or light style.variant(str): One of filled, outlined (default), or standard.
Styling#
sx(dict): Component level styling API.theme_config(dict): Theming API.
Aliases#
For compatibility with Panel certain parameters are allowed as aliases:
button_style: Alias forvariantbutton_type: Alias forcolorname: Alias forlabel
Basic Usage#
The MultiChoice widget allows selecting multiple values from a list of options:
multi_choice = pmui.MultiChoice(label='MultiChoice', value=['Apple', 'Pear'],
options=['Apple', 'Banana', 'Pear', 'Strawberry'])
pmui.Column(multi_choice, height=250)
MultiChoice.value returns a list of the currently selected options:
multi_choice.value
The options parameter also accepts a dictionary whose keys are going to be the labels of the dropdown menu.
ages = pmui.MultiChoice(
label='Ages', options={'Ten': 10, 'Twenty': 20, 'Thirty': 30}, height=200
)
ages
ages.value
Updating the value will display the right label.
ages.value = [20, 30]
Filled and Standard Variants#
pmui.Row(
pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], variant="standard"),
pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], variant="filled"),
height=200
)
Chips#
By default the selections are rendered as chips, this can be disabled with chip=False, alternatively the chip variant can be toggled with solid=False:
pmui.Row(
pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], chip=False),
pmui.MultiChoice(label='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], solid=False)
)
Colors#
pn.FlexBox(*[pmui.MultiChoice(
label=color, value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'], color=color
) for color in pmui.Select.param.color.objects])
Disabled & Loading#
Like all widgets the MultiChoice supports disabled and loading states:
pmui.MultiChoice(label='Ages', options=['Ten', 'Twenty', 'Thirty'], disabled=True, loading=True)
Searchable#
You can make the MultiChoice widget searchable.
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, height=350)
You can configure whether options are filtered or merely highlighted on search.
pmui.Row(
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, filter_on_search=True),
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], searchable=True, filter_on_search=False),
height=350
)
You may provide a default string to filter on:
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], searchable=True, filter_str="F", height=250)
Dropdown Height and Open State#
You may control the dropdown height and the drowdown open state
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], dropdown_height=200, dropdown_open=True, height=250)
Disabled Options#
A subset of the displayed items can be disabled with disabled_options. The widget value cannot be set to one of the disabled_options, either programmatrically or with the user interface.
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty'], disabled_options=['Twenty'], height=200)
Bookmarks#
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty'], bookmarks=['Ten', 'Fourty'], height=250).show()
Launching server at http://localhost:49530
API Reference#
Parameters#
The MultiChoice widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:
pmui.MultiChoice(label='Age', options=['Ten', 'Twenty', 'Thirty', 'Fourty', 'Fifty']).api(jslink=True)
References#
Panel Documentation:
How-to guides on interactivity - Learn how to add interactivity to your applications using widgets
Setting up callbacks and links - Connect parameters between components and create reactive interfaces
Declarative UIs with Param - Build parameter-driven applications
Material UI Select:
Material UI Select Reference - Complete documentation for the underlying Material UI component
Material UI Select API - Detailed API reference and configuration options
pmui.Row(multi_choice.controls(jslink=True), multi_choice)
Download this notebook from GitHub (right-click to download).