Hi @Jurgita
One way to save the state is using session_state. I tried this code and seems to be what you need:
if "option" not in st.session_state:
st.session_state["option"] = None
with st.form("input"):
selected_options = st.sidebar.multiselect(
"Select option:", ["Option1", "Option2", "Option3"], default="Option1")
text = st.text_area("Paste text here", height=350)
submit_button = st.form_submit_button(label="Extract data")
if submit_button:
# Check that text field is not empty
if not text.strip():
st.error("WARNING: Please enter text")
else:
with st.spinner(text = "Extracting information…"):
sleep(3)
st.session_state["option"] = selected_options
st.write("You selected: {} - inside submit_button".format(selected_options))
st.write(text)
if st.session_state["option"] is not None:
st.write("You selected: {} - outside submit_button".format(st.session_state["option"]))
However, it seems that changing input in multiselect causes the app to re-run and clear the output before clicking the button.
Yes, this is a fundamental property of the Streamlit architecture. You can use cache, session_state or IO operations to create an state machine or applications that preserve the state and other logics. I recommend to read this comment that is related about this characteristic