How can I share variables across pages on my multi-page Dash app?

I am planning to create a multi-page Dash app in which different pages will read from the same DataFrame. I could create the DataFrame via a SQL query on each page, but that seems inefficient compared to creating it once and then accessing it across pages. Similarly, I would like to establish certain variables on a single page that I could then import into other pages.

What would be the best way to access the same DataFrame or variable on different pages within my app?

Hello @KBurchfiel,

The simplest way would to probably be sharing a dcc.Store across all the pages by having it in the overall app’s layout. :slight_smile:

Hello @jinnyzor ,

Thanks for recommending dcc.Store. If I’m interpreting the documentation correctly, it looks like trying to send more than 2 MB within a browser setting may be risky (depending on users’ browser limitations). Therefore, I’m now thinking of just placing all of my pages within the same file, as shown here. This makes for a pretty long file, but at least all of my pages can access the same data sources and variables without any need for

Are there any limitations with the single-page approach besides the fact that it makes the code base a bit harder to read/interpret?

You could look into server side caching of the store here, and keep them separate for easier to digest flows. :grin:

If you are talking about a global variable that will never change, you can import them to all the other pages if you absolutely can’t use the other two options.

1 Like