Sure, hope the below works:
app.py
import dash
from dash import html, dcc
import dash_bootstrap_components as dbc
from datetime import datetime as dt
# default bootstrap theme
app = dash.Dash(__name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True)
#sidebar
SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "16rem",
"padding": "2rem 1rem",
"color": "#7F7F7F",
"background-color": "#EBEBEB"}
# the styles for the main content position it to the right of the sidebar and
# add some padding.
CONTENT_STYLE = {
"margin-left": "18rem",
"margin-right": "2rem",
"padding": "2rem 1rem",}
sidebar = html.Div(
[
html.Hr(),
dbc.Nav(
[
dbc.NavLink("Home", href="/", active="exact"),
dbc.NavLink("Pages 1", href="/pages_1", active="exact")
],
vertical=True,
pills=True,
),
],
style=SIDEBAR_STYLE,
)
navbar = dbc.Navbar()
# content from pages
content = html.Div(dash.page_container, style=CONTENT_STYLE)
app.layout = html.Div([
sidebar, navbar,
dcc.Location(id="url"),
dcc.Loading(id='load',
type='default',
children=[
html.Div([dcc.Store(id='data_memory'),
dcc.Store(id='ccy_memory')])
], fullscreen=True),
dbc.Col(
html.Div(html.H3('My App:', style={'fontSize': 20}),
style={'margin-top': '10px','padding-left': '130px'}),
width={'size': 6, 'offset': 1}),
dbc.Row([
dbc.Col(html.Div(dcc.DatePickerSingle(id='date_picker',
max_date_allowed=dt.date(dt.today()),
initial_visible_month=dt.date(dt.today()),
display_format='MMM Do, YY',
placeholder='Select date',
persistence=True,
persistence_type='session',
persisted_props=['date'],
style={'margin-bottom': '10px','padding-left': '130px'})),
width={'size': 1, 'offset': 1}),
dbc.Col(html.Div(
dbc.Button("Refresh Trades", id="button_eur", className="me-1"), style={'margin-top': '6px'}),
width={'size': 2, 'offset': 1})
]
), content])
if __name__ == "__main__":
app.run(debug=True)
pages_1.py
import dash
from dash import dcc, html, callback
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
import plotly_express as px
import pandas as pd
dash.register_page(
__name__,
path='/pages_1',
title='Page 1',
name='Page 1'
)
layout = html.Div([
html.Hr(),
html.H3("Page 1"),
dbc.Row(
dbc.Col(
html.Div(html.H3('DropDown Below:', style={'fontSize': 20}),
style={'padding-left': '10px', 'margin-top': '20px'}),
width={'size': 6})),
# File selection dropdown
dbc.Row(
dbc.Col(
html.Div(dcc.Dropdown(id='ccy_dropdown',
multi=False,
placeholder='Select currency'),
style={'padding-left': '10px'}),
width={'size': 2})),
dbc.Row(
dbc.Col(
html.Div(dcc.Dropdown(id='fund_dropdown',
multi=False,
placeholder='Select fund',
options=[{'label': c, 'value': c} for c in ['One', 'Two']],
value='One'),
style={'padding-left': '10px'}),
width={'size': 2})),
dbc.Row(
dbc.Col(
html.Div(
dcc.Graph(id='fx_points_fig', style={'width': '95vh', 'height': '95vh'}
),
style={'margin-top': '50px', 'width': '95%'}
)
)
)
]
)
@callback([Output('data_memory', 'data'), Output('ccy_dropdown', 'options')],
[Input('button_eur', 'n_clicks'), State('date_picker', 'date')], prevent_initial_call=True)
def update_latest_trades(but, date_value):
if date_value is None or but is None:
raise PreventUpdate
try:
datasets = {'data': 3}
dd_options = [{'label': c, 'value': c} for c in ['One','Two']]
return datasets, dd_options
except:
return None, None
@callback(Output('fx_points_fig', 'figure'),
[Input('ccy_dropdown', 'value'), Input('button_eur', 'n_clicks'),
Input('fund_dropdown', 'value'), State('data_memory', 'data')],prevent_initial_call=True)
def generate_fx_points_table(ccy, n, fund, data):
if ccy is None:
raise PreventUpdate
df = pd.DaraFrame(data=[['One',2,3],['Two',4,5]], columns = ['Fund','Currency','Points'])
fig = px.scatter(df.loc[df['Fund'].isin([fund])], x='Currency', y="Points")
return fig
Tried to make the example as min as possible, thanks a lot for your help here. The app was working before I tried using the dash pages. Looks like there was a similar discussion here but no solution: 📣 Dash v1.11.0 Release - Introducing Pattern-Matching Callbacks - #2 by chriddyp