Hide or Collapse Widgets Upon Submit

Hello! Very new to streamlit but really enjoying learning more and working with this amazing product.

Iโ€™m attempting to make a simple interface that allows for a user to fine tune some elements for song recommendations.

Apologies if there is already an existing thread for this, was unable to locate anything concrete. I was wondering how one would be able to collapse, hide, or delete a widget upon button click. Ideally, after pressing โ€œGet recommendationsโ€ Iโ€™d like the multiselect and other widgets to be hidden or deleted.

I currently have:

filter_options = st.multiselect("Select Desired Filters", ["Tempo", "Key", "Danceability", "Energy", "Instrumentalness", "Valence"], key='1')
final_filters = get_filters(filter_options)
if st.button("Get Recommendations ๐ŸŽต"):
   r = get_recs(final_filters, search_track_dict)

where the widgets used for filtering are created and values from them are retrieved in the call to get_filters(). Not sure if there is a way to do this utilizing st.empty() or other, but any help would be appreciated. Thanks!

streamlit v 0.71, python 3.9

Hi @pkbro!

Welcome to the Streamlit Community!!! :partying_face: :partying_face: :partying_face: :partying_face: :partying_face: :tada:

I think the best option for this would be to use the st.beta_expander() function. You can have it initiate as open and then once the user has selected all of the options they can close the expander without rerunning your script (and losing the users selections).

Checkout out community post here
Checkout the Documentation here

Happy Streamlit-ing!
Marisa

4 Likes

Here You go -

var1 = st.empty()
var2 = st.empty()
var3 = st.empty()

filter_options = var1 .multiselect("Select Desired Filters", ["Tempo", "Key", "Danceability", "Energy", "Instrumentalness", "Valence"], key='1')
final_filters = get_filters(filter_options)
if st.button("Get Recommendations ๐ŸŽต"):
   r = get_recs(final_filters, search_track_dict)
   var1.empty()
   var2.empty()
   var3.empty()

But it looks nasty if you ask me. There is another way using beta_container() which you can see here
which would be elegant but that has succumbed to a glitch.