I found this post, which helped me solve this problem. I changed the app to be:
import streamlit as st
import pandas as pd
st.elements.utils._shown_default_value_warning=True
df = pd.DataFrame({'text' : ['text1', 'text2', 'text3']*3})
if 'key1' in st.session_state:
st.session_state.key1 = st.session_state.key1
if 'fils' not in st.session_state:
st.session_state.fils = list(df['text'].unique())
st.session_state.fils = st.multiselect(
f"Values for text",
df['text'].unique(),
default=st.session_state.fils,
key='key1'
)
df2 = df[df['text'].isin(st.session_state.fils)]
st.dataframe(df2)
The st.elements.utils._shown_default_value_warning=True
line is needed to prevent the warning that the solution to the problem caused. If there is a better way of achieving the same outcome of having the defaults dynamically set so that one can navigate to another page and return to the page where the data was filtered and see the latest filters that were applied before navigating away, I would be open to it.