Hi, I would like to know if there is a way to load data in a multi pages streamlit app ?
I mean that I have one file of data that is cleaning,…do I need to repeat this operation in every file of the multi page app ?
Thx.
Not sure what you are asking exactly, but loading data in a multipage application should be no different from loading data in a single page application. What is a “file of data that is cleaning”?
I would like not to do this several time (as there is a multi page number) ie ine the different pages not have to do :
Import pandas as pd
Data = pd.read_excel(file)
Do it just once in a setup file.
Cordialement
You could try using a session state variable to store the dataframe, then it only needs to be loaded once on the main page. You can then call the dataframe or manipulate it from any page:
if 'df_data' not in st.session_state:
st.session_state.df_data = pd.read_excel(path_to_file)
Only one thing you need to be aware of. Lets assume the data is read on page 1 of your app, you just need to make sure that if a user happens to visit page 2 before page 1 that there is a catch somewhere to make sure they visit the first page first that generates the data you need.
Any data available in one page can be made available to the other pages too. There is st.session_state
for session-scoped data and st.cache_data
for data that should persist across sessions.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.