Access dataframe in another page (multipage app)

I have a multi-page app. In the home page I’m reading a csv using Pandas (the file is being uploaded) and displaying it using st.dataframe

I want to also display the data in another page.
The data is displaying in the second page. However, when I go back to the main page. The dataframe is gone from the UI (it’s not persisting in the front-end).

Is there a way to solve this using st.session_state?

Currently, I’m setting the dataframe as a value in the session state.

In home page:

csvFile = st.sidebar.file_uploader("Upload CSV", type=["csv"])

    if csvFile is not None:
        df = pd.read_csv(csvFile)

    if "dataframe" not in st.session_state:
        st.session_state["dataframe"] = df
    st.dataframe(st.session_state.dataframe)

In second page:

if "dataframe" in st.session_state:
    st.table(st.session_state["dataframe"])

Hi @sevensouls, welcome to the Streamlit Community! :wave:

Does the example here help?

Hi @snehankekre, Thank you for help. But this did not work for me. When I go back to page_1. The dataframe is simply gone. Any idea why this is happening?

Thank you!