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:
- 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
MultiSelectvalue with URL paramters.
- disabled (boolean) - disable widget in the sidebar, default is set to
- hidden (boolean) - hide widget in the sidebar, default is set to
Let's create the
MultiSelect widget with
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:
Please note that
?selected=a,b is added at the end of URL address.
Below is a screenshot with example app. Example app is available at docs.runmercury.com/app/multiselect (opens in a new tab).