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?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.