arnaudmiribel / streamlit-extras

Discover, try, install and share Streamlit re-usable bits we call "extras"!
https://extras.streamlit.app
Apache License 2.0
727 stars 124 forks source link

Add stateful button #110

Closed blackary closed 1 year ago

blackary commented 1 year ago

Create a button component where each button press works to toggle the status of the button on and off (as a bonus, could even change the color or something to show the current state).

from streamlit_extras.stateful_button import button

if button("Button1"):
    if button("Button2"):
        if button("Button3"):
            st.write("Button3")       

Right now you can make this work through some fiddling with session state, but it's a fairly manual process https://discuss.streamlit.io/t/3-nested-buttons/30468/2?u=blackary

Simple prototype, without coloring: https://playground.streamlit.app/?q=stateful_button