Dynamically updating the displayed selections in a multiselect

TLDR; How can I update what is shown as “selected” in the multiselect widget? (I am not trying to update options.)

I have a multiselect widget that allows the user to select US counties from the list. They are then shown data about the selected county(ies). As a convenience, I also want to allow the user to click on a st_folium map of counties to add counties to the list.

I can capture the clicks and append the county name to the value list of the multiselect widget, but this does not update what is shown as “selected” in the multiselect widget.

Here is a simplified version

# Create interactive map
map_output = st_folium(counties_map)

# Create multiselect widget
counties_multiselect = st.multiselect(
        "Counties",
        counties_list,
        default=None,
        placeholder="Choose one or more counties",
)

# Add map selection to list of counties selected in widget.
counties_multiselect.append(map_output["county_name"])

# This works fine to add it to the list of selected counties, but it does not show 
# `map_output["county_name"]` as being selected in counties_multiselect, 
# even if the value matches a value that is in `counties_list`.  

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.