API Docs
MultiSelect

MultiSelect

Adds multi-select widget (you can select multiple values).

import mercury as mr
# add select widget
selected = mr.MultiSelect(label="Please select letters", 
                          value=["a", "b"], 
                          choices=["a", "b", "c", "d", "e"])
# access selected values
print(selected.value)
# ["a", "b"]

Running an example code in Mercury:

Mercury App with multiselect widget created in Jupyter Notebook

Parameters

  • value (list of strings) - initial selection.
  • choices (list of strings) - available choices in the widget.
  • label (string) - label near the widget.
  • url_key (string) - set this value if you would like to set MultiSelect value with URL paramters.
  • disabled (boolean) - disable widget in the sidebar, default is set to False.
  • hidden (boolean) - hide widget in the sidebar, default is set to False.

Share widget value in URL

Let's create the MultiSelect widget with url_key="selected":

import mercury as mr
 
app = mr.App(title="MultiSelect", description="Demo of MutiSelect widget", show_code=True)
 
# add widget
selected = mr.MultiSelect(label="Please select letters", 
                          value=["a", "b"], 
                          choices=["a", "b", "c", "d", "e"],
                          url_key="selected")
 
# print widget value
print(selected.value)

You can share the widgets values with other users. Please click the Share button in the sidebar bottom. It will open a dialog with URL.

The URL will look like:

https://your-server-address.com/app/notebook-name?selected=a,b

Please note that ?selected=a,b is added at the end of URL address.

Example App

Below is a screenshot with example app. Example app is available at docs.runmercury.com/app/multiselect (opens in a new tab).

App with multiselect widget

Notebook's code:

Jupyter Notebook with multiselect widget