Summary
When I assign the current selection in a multiselect object to a session_state variable that I feed back into the same multiselect object, it requires me to select a filter twice before it registers (although the first selection works without needing to select twice). A visual of the behavior is below.
Steps to reproduce
Code snippet:
import streamlit as st
import pandas as pd
df = pd.DataFrame({'text' : ['text1', 'text2', 'text3']*5})
if 'fils' not in st.session_state:
st.session_state.fils = None
if st.session_state.fils:
default_value = st.session_state.fils
else:
default_value = list(df['text'].unique())
user_cat_input1 = st.multiselect(
f"Values for text",
df['text'].unique(),
default=default_value,
)
st.session_state.fils = user_cat_input1
df2 = df[df['text'].isin(user_cat_input1)]
st.dataframe(df2)
Expected behavior:
Only need to click once for each filtered item and have the new set of filtered items populate the default of the multiselect.
Actual behavior:
Must click each filter selection twice.
Debug info
- Streamlit version: 1.22
- Python version: 3.9.13
- PyEnv
- OS version: 13.4.1
- Browser version: Chrome and Firefox
Additional information
I am attempting the have the selections remembered and then put into the default selection because I want the user to interact with the filtered data on other pages and be able to return to the filter page and see the previously selected filters. A visual of this process is below.
I am open to better ways of achieving the same outcome of having the filters remembered when returning to the filter page.