Nested Buttons with Session State

Hi,
I haven’t been able to follow the developments with ‘session state’ but I think I know that we can use that to solve my problem.

How can I reach the successful part with these nested buttons?

import streamlit as st

a = st.button("Button 1")

if a:
    b = st.button("Button 2")
    if b:
        st.write("Successful.")

Hi @Berk_Demir,

My advice would be to put a key in st.session_state that changes once button 1 is pressed. Then the if statement that creates the second button, would depend on the value assigned to that key in the session state and not on the return value from the button.

You can learn the syntax of this through our example in the docs on making a counter (It works on the same principle, you probably just want your value to be True or False and not an integer)!

Happy Streamlit-ing!
Marisa