Data caching across multipage app

Hi, I am trying to create an app with multiple pages which perform different statistical tests on the same dataset. What I want is to have a homepage where the data is loaded and then a number of other pages dedicated to different statistical procedures.

What I have now is adapted from the awesome-streamlit project. I currently have a home page for general landing and loading the data, a data viz page which was for visualising raw data but also needs to reload the data, and a stats test which again needs to reload the data then runs a simple sklearn function.

I have my main which looks like this:

import streamlit as st

import awesome_streamlit as ast
import od_pages.home
import od_pages.nntest
import od_pages.dataread

    "Home": od_pages.home,
    "Data Viz": od_pages.dataread,
    "Stats Test A": od_pages.nntest,

def main():
    """Main function of the App"""
    selection ="Go to", list(PAGES.keys()))

    page = PAGES[selection]

    with st.spinner(f"Loading {selection} ..."):

    st.sidebar.title("Folder location")
    fpath = st.sidebar.text_input(
        "Data filepath"
        This is an info box

if __name__ == "__main__":

What I want is for the data to be loaded in the and then to become a global variable such that it can be used in Data Viz and Stats Test A. My looks like this:

import streamlit as st
import glob

def get_data(filelist):
    data, freqs, time, pi_dict_list = <readdata>(filelist)

    return data, freqs, time, pi_dict_list

def write():
    """Used to write the page in the file"""
    with st.spinner("Loading Home ..."):
        # Prototyping environment of stat tests
        blah blah
        filelist = glob.glob(<folder>)
        data, freqs, time, pi_dict_list = get_data(filelist)

Despite adding in the caching, everytime I renavigate to home, the page is rewrote so the data is reloaded.

Does anyone have any advice on:

  1. How I can pass data between pages?
  2. How I can cache the pages such as to not rewrite them everytime I move off and then back onto them?

Thank you!