Hello guys,
I am new to dash and i need to fix the default home page of my Dashboard to the following. Any advise on how to proceed. I need the default page to be - dbc.NavLink(“Main Page”, href="/page-1", id=“page-1-link”) however it always starts with Page-2.
Please assist.
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP,['https://codepen.io/chriddyp/pen/bWLwgP.css']])
SIDEBAR_STYLE = {
"position": "fixed",
"top": 0,
"left": 0,
"bottom": 0,
"width": "15rem",
"padding": "2rem 1rem",
"background-color": "#abc7ed",
}
CONTENT_STYLE = {
"margin-left": "18rem",
"margin-right": "2rem",
"padding": "2rem 1rem",
}
sidebar = html.Div(
[
html.H3("Premium Content", className="display-4"),
dcc.Upload(html.Button('Upload File')),
html.Hr(),
html.P(
"World Wide Dashboard", className="lead"
),
dbc.Nav(
[
dbc.NavLink("Main Page", href="/page-1", id="page-1-link"),
dbc.NavLink("Premium Queue > 50", href="/page-2", id="page-2-link"),
dbc.NavLink("HV/HP", href="/page-3", id="page-3-link"),
dbc.DropdownMenu([dbc.DropdownMenuItem("Premium", id ='Premium'), dbc.DropdownMenuItem("HV/HP", id = 'Premium1')],
label="Savings",
nav=True,
)
],
vertical=True,
pills=True,
),
],
style=SIDEBAR_STYLE,
)
content = html.Div(id="page-content", style=CONTENT_STYLE,
children= html.Div([
]))
app.layout = html.Div([dcc.Location(id="url"), sidebar, content])
@app.callback(
[Output(f"page-{i}-link", "active") for i in range(1, 4)],
[Input("url", "pathname")],
)
def toggle_active_links(pathname):
if pathname == "/":
# Treat page 1 as the homepage / index
return True, False, False, False
return [pathname == f"/page-{i}" for i in range(1, 4)]