Keep Uploaded File Between Pages

I have an app with 2 pages: a homepage (parent folder) and page 2 (child folder of the within parent folder). The homepage has a fileuploader to upload and display a csv. This works, but when I switch to page 2, the back to homepage, the uploaded file has disappeared and I have to reupload. How do I use Session State to keep the uploaded file from disappearing when I go between pages?

Homepage, initial upload:

Page 2, displays data uploaded from Homepage:

Back to Homepage after visting Page 2, upload and dataframe have disapeared:

Homepage code:


import pandas as pd
import streamlit as st
    page_title = "Multipage App",

df_src = r"C:\Users\krakl\Jupyter\streamlit\strong (12).csv"
temp_data = pd.read_csv(df_src)
cols = temp_data.columns

st.title("Upload Data")
st.sidebar.success("Select a page")

# Allow only .csv and .xlsx files to be uploaded
uploaded_file = st.file_uploader(
    "Upload spreadsheet", 
    type=["csv", "xlsx",'txt'],
# Check if file was uploaded
if uploaded_file is not None:
    st.session_state['df_result'] = pd.read_csv(uploaded_file)

    # Work with the dataframe
    wkt_count = len(st.session_state['df_result']['Date'].unique())

Page 2 code:


import streamlit as st

st.markdown('page 2 test')


Your help is appreciated, thank you.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.