I'm following the guidance to create a multi-page app in the dash documentation: https://dash.plotly.com/urls
My issue is that the data is in a total of four dataframes, and each of the three pages in my app uses more than one of these to visualize content. I'm trying to avoid reloading the dataframes each time I call one of the pages. Is this possible? How?
Currently, I'm trying to first load the df's using a function in my index.py, then load the other pages:
df_fz, df_md, df_auf, df_mat = get_dfs()
from apps import app1, app2, app3
[...]
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/app1':
return app1.layout
elif pathname == '/app2':
return app2.layout
else:
return app3.layout
Each of app1 to app3 uses the dataframes as if they were loaded at the top of their scripts, but this code as is is throwing an error because the df's are not defined. A minimal example of what app3 could look like:
layout = html.Div([
html.H3('App 3'),
dcc.Dropdown(
id='app-3-dropdown',
options=[
{'label': 'App 3 - {}'.format(i), 'value': i} for i in [df_fz.Value]
]
),
html.Div(id='app-3-display-value'),
])
@app.callback(
Output('app-3-display-value', 'children'),
[Input('app-3-dropdown', 'value')])
def display_value(value):
return 'You have selected "{}" but in App 3'.format(value)