Summary
I am getting familiar using streamlit (and therefore with session states). I have a small app, consisting of a “Button A”, that enables a small text, and a “Button B”. Using “Button B”, I want to hide the small text and “Button B” itself, at the first click. So far, I can achieve this, but clicking twice on “Button B”; I should only click it once.
Steps to reproduce
Code snippet:
import streamlit as st
if 'display_result' not in st.session_state:
st.session_state.display_result = False
if 'reset' not in st.session_state:
st.session_state.reset = False
st.header("My Demo App")
result="My Custom Text"
button_a = st.button('Button A')
if button_a :
st.session_state.display_result = True
if st.session_state.display_result:
st.write(result)
button_b = st.button('Button B')
if button_b:
st.session_state.reset = True
if st.session_state.reset:
st.session_state.display_result=False
st.session_state.reset=False
No additional steps are needed, just run the previous code snippet.
Expected behavior:
To display result
and Button B
when Button A
is clicked, and to hide result
and Button B
when Button B
is clicked. Any button should be clicked ONCE to get the corresponding action.
Actual behavior:
result
and Button B
are displayed when Button A
is clicked ONCE (this is OK), BUT they get hidden when Button B
is clicked TWICE (this is not OK).
Debug info
- Streamlit version: 1.22.0
- Python version: 3.10.6
- Using PipEnv (Pip version 23.1.2)
- OS version: Linux Mint 21.1 Vera
- Browser version: Mozilla Firefox for Linux Mint-001, version 112.0.2 (64 bit)
Requirements file
Not needed, the script only uses aforementioned Streamlit version.
Links
Does not apply.
Additional information
Does not apply.