I have implemented a Sidebar in my application using dbc.Nav
. I am using dbc.NavLink
and render the layout
component of the page to update content.
I have a couple of questions -
-
dbc.NavLink
takeshref
as an argument which is astring
. Is there a way to pass a list of strings? I’d like to update / render samelayout
forHome
andNavLink1
? -
How do I select a
dbc.NavLink
option by default?
My code below for illustration:
import dash
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
app.layout = html.Div([
html.Div(
[
html.H4("Sidebar", style={"textAlign":"center"}),
html.Hr(),
dbc.Nav(
[
dbc.NavLink("opt1", href="/page-1", active="partial"),
dbc.NavLink("opt2", href="/page-2", active="partial"),
dbc.NavLink("opt3", href="/page-3", disabled=True),
],
vertical=True,
fill=True,
pills=True,
),
],
)
dcc.Location(id='url'),
html.Div(id='page-content'),
])
# Callbacks
# Render page content
@application.callback(Output("page-content", "children"),
[
Input('url', 'pathname')
]
)
def display_content(pathname):
if pathname == "/":
return sub.layout
elif pathname == "/home":
return sub.layout
elif pathname == "/opt1":
return sub.layout
else:
return dash.no_update
I read through the docs but didn’t find info on what I am looking for. Nav - dbc docs