HI All,
I’m trying to use Dash Pages with a Tabbed page format. I have followed the Plotly Dash documentation and am sure my folder structure is correct: app.py in main folder and three .py files in a pages folder. I’m sure the pages files are correctly format because they are from Adam’s GitHub. Typically:
import dash
from dash import dcc, html
import plotly.express as px
dash.register_page(__name__, path='/')
df = px.data.gapminder()
layout = html.Div(
[
dcc.Dropdown([x for x in df.continent.unique()], id='cont-choice', style={'width':'50%'}),
dcc.Graph(id='line-fig',
figure=px.histogram(df, x='continent', y='lifeExp', histfunc='avg'))
]
)
I just cannot seem to get the link between app.py and the pages file to work. Here’s my code:
import dash
from dash import html, dcc, callback, Input, Output
app = dash.Dash(__name__, use_pages=True)
app.layout = html.Div(
[
html.Div("Python Multipage App with Dash", style={'fontSize':50, 'textAlign':'center'}),
dcc.Tabs(id='tabs', value='tab-1', children=[
dcc.Tab(label='Tab one', value='tab-1'),
dcc.Tab(label='Tab two', value='tab-2')
]),
# content of each page
dash.page_container
], id='mainDiv'
)
@callback(
Output('mainDiv', 'children'),
Input('tabs', 'value')
)
def render_content(tab):
if tab == 'tab-1':
return html.Div(dcc.Link(href=dash.page_registry['pages./']['path']), refresh=True)
if tab == 'tab-2':
return html.Div(dcc.Link(href=dash.page_registry['pages.pg2']['path']), refresh=True)
if __name__ == "__main__":
app.run(debug=True, port=8001)
I’m sure I’m missing something. Can anyone help? Thanks!