I have a multipage app with a navigation sidebar that links to 3 other pages I can navigate to. The entrypoint file has a sidebar with the navigation pages in a sidebar which also has a checkbox widget. I set the value of this widget when this widget gets created to True .
When I navigate to one of the navigation pages, I would like to change the above widget value to False in the entrypoint file. I tried to do this by creating a session_state variable in the entrypoint file and using it to populate the widget’s value. When I try to change the value of this variable session_state on the navigated page (hoping it will change the widget value), I get an error.
Code in entrypoint file:
if "one" not in st.session_state:
st.session_state["one"] = True
chk = st.checkbox("My Options", value=st.session_state["one"], key='one')
File I navigate to has this code:
if "one" in st.session_state:
st.session_state["one"] = False
st.write("st.session_state['one'] has been changed to False")
Error I get:
StreamlitAPIException: st.session_state.one cannot be modified after the widget with key one is instantiated.
Please tell me how I can get the desired effect.