I’m working on an app intended to be used to update a json file. I’ve read a json file initialized each json field as a state and create widgets with the same key and after submitting with the forms I would use the state to create a new json file with the newer field values.
The structure is similar to this example
import streamlit as st
keys = ["a", "b", "c", "d", "e"]
# We know that:
# a -> 0
# b -> 1
# c -> 2
# d -> 3
# e -> 4
for idx, key in enumerate(keys):
if key not in st.session_state:
st.session_state[key] = idx
st.write("# Some Header")
with st.form("Form 1"):
with st.expander("First Form"):
st.slider("a", 0, 10, step=1, key= "a")
st.slider("b", 0, 10, step=1, key='b')
st.form_submit_button("Submit Here I")
with st.form("Form 2"):
with st.expander("Second Form"):
st.slider("c", -1, 10, step=1, key= "c")
st.slider("d", -1, 10, step=1, key='d')
st.form_submit_button("Submit Here II")
with st.expander("Other Thin outside form"):
st.slider("e", 0, 10, step=1, key= "e")
st.button("Do something")
st.write([f"{key}: {st.session_state[key]}" for key in sorted(st.session_state.keys())])
Everything was okay until I’ve noticed that if I submit one of the forms without opening all the expanders the value that appears in the sliders would be the min_value instead of the state value.
Any help would be very appreciated