Hey @abick here an example where I create a dropdown in a Navbar:
dbc.DropdownMenu(
[
dbc.DropdownMenuItem(
children=page['name'],
href=page['path']
)
for page in dash.page_registry.values()
if page['name'] != 'Not found 404'
],
align_end=True,
label='Menu',
color='primary',
style={'marginLeft': '15px'},
)
Full MRE:
import dash
from dash import html
import dash_bootstrap_components as dbc
external_stylesheets = [
dbc.themes.SLATE,
dbc.icons.FONT_AWESOME,
]
# initiate app
app = dash.Dash(
__name__,
use_pages=True,
external_stylesheets=external_stylesheets,
)
# create a navbar. Includes logo and menu drop down
navbar = dbc.Navbar(
id='navbar',
children=[
dbc.NavbarBrand(
html.A(
[
html.I(
className="fa-brands fa-github d-inline",
style={'color': 'white', 'height': '50px'}
),
],
href="https://github.com",
target="_blank",
className='align-items-center text-decoration-none text-black',
),
className="me-auto", # me-auto pushes other elements to the right
style={"margin-left": "10px"},
),
dbc.Nav(
dbc.DropdownMenu(
[
dbc.DropdownMenuItem(
children=page['name'],
href=page['path']
)
for page in dash.page_registry.values()
if page['name'] != 'Not found 404'
],
align_end=True,
label='Menu',
color='primary',
style={'marginLeft': '15px'},
),
navbar=True,
),
],
color='primary',
className='mb-0',
# ^^ no margin on bottom
style={'height': '50px'}
)
app.layout = html.Div(
[
navbar,
dash.page_container,
],
)
if __name__ == "__main__":
app.run(debug=True)