Multiselect Field in Sidebar Ignores Selection and Refreshes


I am writing an app that retrieves data from a sql server and stores it in a dataframe. The user is then allowed to use two filters to filter through this dataframe and look at KPIs based on the filtered data.
The problem I am facing now is with one of the mltiselect filters. When I try to add a selection, the app does take it, it simply refreshes and revers back to the default selection/option.

Code snippet:

st.sidebar.header('Data Control')

# Selecting Distribution Center:
distro_select = st.sidebar.multiselect(
    "Select Distro ID#:",

# Selecting Staging ID:
store_select = st.sidebar.multiselect(
    "Select Store #:",

# Query the raw db based on user filters from the sidebar:
def filtered_data(query_df, distro_select, store_select):
    filtered = query_df.query(
        "SHIPPING_TO in @store_select & WAREHOUSE_ID in @distro_select")
    return filtered
filtered = filtered_data(query_df, distro_select, store_select)

Expected behavior:

Generate the dataframe based on the selection.

Actual behavior:

overrides my selection and refreshes the app.

Debug info

  • Streamlit version: 1.17.0
  • Python version: 3.11.1
  • Using venv
  • OS version: windows

I’m not 100% sure I’m interpreting this as you intend, so could you show a bit more code so I can see how you are handling query_df between page loads?

If you are updating df_query between selections, then you will be passing a different list of options to the widgets and you could be seeing them reinitialize and thus “going back to default.”

If you expand the script to show how you load/save df_query and may give a simple data frame for me to use as input, I’d be happy to test it out.


I solved this issue by caching the query’s result before using it in the app using the python module ‘pickle’. You can see more detailed code and the solution in this thread: