Problem with multiselect erase button

Hi everyone, I have a problem. I created a button for clear multiselects, but when I run the button, it creates new multiselect with errased filters, I don鈥檛 want to create new multiselect filters I only want to clean old filters multiselect. In the next section, you can see the link to my code and then you can see the specific part with the button.

I appreciate your comments! Analytics_Portfolio/STREAMLIT/Domestic_Abuse/ at main 路 miguelmag1/Analytics_Portfolio 路 GitHub

  1. Specific code part:

if st.sidebar.button(鈥淟impiar filtros鈥):
genero = st.sidebar.multiselect(
"Seleccionar Genero: ",


agrupacion_edad = st.sidebar.multiselect(
    label='Seleccione Grupo Etario',


departamento = st.sidebar.multiselect(
    label='Seleccione departamento',


mpio = st.sidebar.multiselect(
    label='Seleccione municipio',


Hi @Miguelmag

Perhaps you can try this:

  1. Store your multiselect widget in a session state
if "genero" not in st.session_state.keys():
    st.session_state. genero = df_violencia_int_2023[鈥楪ENERO鈥橾.unique()
  1. Overwrite the session state of the multiselect widget when you want to clear its filter
def clear_genero():
    st.session_state.genero = df_violencia_int_2023[鈥楪ENERO鈥橾.unique()

st.sidebar.button('Clear filter', on_click=clear_genero)

Hope this helps!

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