i have a multi pages Streamlit app. I would like to have variable that are globals ie that are defined in a page and known everywhere.
How to define this type of variable ?
How to get its value in other pages ?
How to test if the variable is defined ?
Just to finish my variable could be a variable or a dataframe
I am going to verify if it’s that what I was looking for.
One more question :
Is it possible if the variable has not been loaded in the page, to force the app to go to the page where it will be loaded.
I mean, imagine that, I load my data in page call page1 and if the user open the app and directly goes to page2, I suppose that I will get an error message. How to tell streamlit that the user should go to page1 and launch this page.
the selected_indices existed when I change once a page but when I rechange my page, it is no longer found…
Second question how to rememorize my previous choice in my parameter page each time I change page in my app ?
I hope you understand my problem and you could help me.
Hi @Jacques2101, there is a common issue with widgets and multipage apps. Normally widget state is preserved (e.g. if you click a checkbox it stays clicked), but if the widgets are removed from the page (e.g. if you switch pages) their values are lost. There is an easy workaround which is to stick this at the top of every page in your app.
for k, v in st.session_state.items():
st.session_state[k] = v