button1 = st.button('click')
if button1:
st.write('button 1 is working')
button2 = st.button('click me')
if button2:
st.write('button2 is working')
When I press button 1, I want it to print âbutton 1 is workingâ and show button2. And if I click on button 2, I want the button1 output to remain on the page + I want button 2 output.
That is a popular question! Buttons donât remember their state, so they will only be True immediately after being clicked (and hence a nested button with go away when clicked because the parent will go back to False). You can use session state and callback functions to extend the functionality.
I did a little introduction on extending widget functionality with session state here
Hereâs a few cases other users have had with nested buttons (first link goes to my reply with sample code to show a basic case)
Every time you interact with something, the page reloads. So when you click a button, the page will reload with that button being True. As soon as you do anything else, the page will reload with that button being False. Itâs not so much a length of time, just that it wonât survive past any other activity.