Hi there,
When using a st.form the content of the form is updated correctly in the st.session_state.
However variables set by other code after clicking the submit button won’t show up in the st.session_state, but they will lag behind by 1 value. Is there any way to make sure values that are changed will show up when the page is reloaded instead of having a delayed change?
Code te reproduce
If you run the following code you will notice that the st.sesson_state.LastChanged value will be empty the first time after you click the submit button.
The second time it is clicked the old value will show up from when you first clicked it (keep note of the time).
from datetime import datetime
import streamlit as st
if 'LastChanged' not in st.session_state:
st.session_state['LastChanged'] = ''
st.markdown("# Test with form submit button")
st.write("st.session_state")
st.write(st.session_state)
form = st.form("Settings")
label = "Test"
CurrentValue = 0
options = ["1", "2"]
index = 0
form.radio(label, options, index=index,
key=label, help=None, horizontal=False)
submitted = form.form_submit_button("Submit")
if submitted:
st.session_state['LastChanged'] = str(datetime.now().strftime('%Y-%m-%d %H_%M_%S.%f'))