Hey @Codeguyross,
I’m assuming you meant button
instead of checkbox, since you don’t need SessionState for checkboxes because they preserve their return values on script rerun :
import streamlit as st
if st.checkbox('Click me'):
if st.checkbox("Click me too !"):
st.write("Hello world")
Whereas buttons don’t, so when you click the first one it gets to True
but when you click the second one, the first one goes back to None
and doesn’t pass the first check. So for this case :
- First copy the SessionState gist in a
SessionState.py
file next to yourapp.py
script. - Initialize a state to
False
. When you click the first button pass it to True and use it to bypass the check of the first button next time.
import SessionState
import streamlit as st
session_state = SessionState.get(checkboxed=False)
if st.button('Click me') or session_state.checkboxed:
session_state.checkboxed = True
if st.button("Click me too !"):
st.write("Hello world")
Here is another thread for another example.
Tested in Streamlit 0.63 and 0.64.
Hope that helps,
Fanilo