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.