Delete widgets

Hello all,

I am using streamlit to build a web app. I need to design an interactive web-app where I need to remove(delete) a set of widgets after a button click and replace them with new ones.

Please let me know if you find a solution. Thanks in advance.

PS: Using empty() or beta_containers did not solve my issue.

Maybe you can use pythonโ€™s del operator. Will something like this work for you?

table_data = {'Column 1': [1, 2], 'Column 2': [3, 4]}

if st.button('delet dis'):
    del table_data
    st.write('mr button has delet for u')
    
try:
    st.write(pd.DataFrame(data=table_data))
except:
    pass


1 Like

Thanks for creating the sandbox @sjd333! :smiley: Itโ€™s awesome to be able to try something out quickly in the browser! :clap:

is it possible to delete a button after click this button ?

sovled by using st.empty(), but if there is a better way ?

placeholder = st.empty()
isclick = placeholder.button('delete this button')
if isclick:
    placeholder.empty()
5 Likes

Thank you so much @jackie_xiao, this helped me a lot.