Add all options button in multiselect

Hi everyone!! :wave:

I’m developing an app which contains a multiselect widget with 10 options. Is there an alternative to add a button that adds all the options to avoid selecting them one by one?

Try adding a previous button to the multiselect, but using another widget resets the selection. Here is an example code:

import streamlit as st

if st.sidebar.button('Add all years'):

    year_filter = st.sidebar.multiselect('Select a year',[2000,2001,2002,2003,2004], default=[2000,2001,2002,2003,2004])

else:

    year_filter = st.sidebar.multiselect('Select a year',[2000,2001,2002,2003,2004], default=[2000])


type_filter = st.sidebar.multiselect('Choose a type',['Control','Experimental'], default=['Experimental'])

st.write(year_filter, type_filter)
1 Like