Hi , I have hard time caching my uploaded file, I want to used it on all of the others pages of my application, the user upload the source file on the app main page.
The problem is that everytime that I change page it clears the data that have been uploaded previously.
Here’s what the source code of main page looks like:
uploaded_f = st.sidebar.file_uploader(‘Choose a XLSX file’, type=[‘xlsx’, ‘xlsb’])
if uploaded_f: @st.experimental_memo(suppress_st_warning=True) def kimiwa(): uploaded_file = uploaded_f return uploaded_file
and for one of the page that will be exploiting it
Here’s an example of caching an uploaded file in a multipage setting, based on your code. When switching pages, the uploaded data is preserved and not cleared:
Code
page_1.py
import streamlit as st
import pandas as pd
uploaded_f = st.sidebar.file_uploader("Choose a CSV file", type=["csv"])
if uploaded_f is not None:
@st.experimental_memo
def kimiwa():
uploaded_file = uploaded_f
return uploaded_file
pages/page_2.py
import streamlit as st
import pandas as pd
from page_1 import kimiwa # import the function from main page
uploaded_file = kimiwa()
@st.experimental_memo
def corridors():
df = pd.read_csv(uploaded_file)
return df
if uploaded_file is not None:
corridors = corridors()
st.write(corridors)
@snehankekre it works perfectly sir, can’t thank you enough for your help, it really made my night. Hope that your solution will benefit many other people like @Ishtiak_Ahmed aswell.
Thanks @snehankekre for your reply. It fixed my problem with transferring the uploaded data information to the new page. However, when I upload a file, it remains inside the memory. Regardless of what I upload later in the first page, the information on the second page do not change. I mean the second page still keeps the information of the very first uploaded file. Can you help me on how to fix this issue?