Hi,
I am working on an application in which the status of the whole page can be saved/loaded to/from a file. To do so I opted to set the value of each widget according to a variable stored in the session state that, in turn, is updated whenever the user changes the widget’s state.
In doing so, however, I stumbled across a strange behavior in which the state of the widget requires a double click by the user to be set correctly.
A minimal example of the problem can be reproduced (streamlit 1.12.2) using the following script:
import streamlit as st
if "X" not in st.session_state:
st.session_state["X"] = False
st.session_state["X"] = st.checkbox("A checkbox", value=st.session_state["X"])
I was wondering if anyone can explain the cause of this behavior and a possible way to prevent it. At the moment I solved the problem by forcing a page rerun on widget change according to:
import streamlit as st
if "X" not in st.session_state:
st.session_state["X"] = False
buffer = st.checkbox("A checkbox", value=st.session_state["X"])
if buffer != st.session_state["X"]:
st.session_state["X"] = buffer
st.experimental_rerun()
Thanks in advance