Summary
This code is to reproducing my issue, i have multiple forms and each form has itβs multi select, while i change multi select βm1β from form 1, multi select βm2β from form2 is getting reset, i would like βm2β persistence itβs last selected values.
Steps to reproduce
Code snippet:
import streamlit as st
def main():
with st.form("form_1"):
selected_m1 = st.multiselect(label="Select ABC",
options=m_1,
key="selected_m1_tmp")
st.form_submit_button("Apply")
with st.form("form_2"):
m2_option = [s for s in m_2 if s.startswith(
tuple(st.session_state.selected_m1_tmp))]
selected_m2 = st.multiselect(label="Select ABC sub",
options=m2_option,
key="selected_m2_tmp")
st.form_submit_button("Apply")
selected_m2
if __name__ == "__main__":
m_1 = ["a", "b", "c"]
m_2 = ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]
main()
Steps to reproduce:
- Run given snippet
- Select βaβ and βbβ in first multi select and click apply
- select βa1β and βb1β in second multi select and click apply
- Now add βcβ to first multi select and click apply
- You will see second multi select is getting reset to empty instead holding previously selected βa1β and βb1β
Expected behavior:
Expected behavior is to persist previous selected values in multi select in form 2 when we change form 1 multi select.
I have already try setting session but was not successful. Thank you.