Press a button do something then press another button do something else

Hi All,

To my understanding you cannot have a button that executes a specific task - in my case it brings data from a database and displays it in my streamlit app- and then another button to use those data fetched in the background in order to display e.g. another dataframe with the aforementioned data analysed in any way.

Is this true?

Apologies if I havent phrased my problem in a straightforward manner but can someone redirect me to another post or any resource available. It is too difficult for me to create an app without refreshing the whole code when clicking on a button.

Thank you

The button in Streamlit is a stateless interactive element. That is, the code will fire the button_pressed event once, and will not remember it in the subsequent re-runs of the script (because button’s state cannot be saved in the visible UI).

The solution is to use st.checkbox() instead of st.button() because it is capable of maintaining (persisting) the pressed state.

Check this thread for more details: