@jinnyzor
I need some help with adding login page to dash app and only show the page links in the Navigation bar based on the user role. I tried to go through the solution you provided above but couldn’t figure out how it can be implemented for my requirement.
My Folder structure is
-pages
–page-1
–page-2
-app.py
I’ve two roles admin and user. Both page links should be displayed in the navigation bar to user with admin role and page-1 link should only be displayed in navigation bar to user with user role.
My app.py file is below
import dash
from dash import html, dcc
import dash_bootstrap_components as dbc
dash_app = dash.Dash(
__name__,
use_pages=True,
suppress_callback_exceptions=True,
external_stylesheets=[dbc.themes.SPACELAB],
)
app = dash_app.server
navbar = dbc.Navbar(
dbc.Container(
[
dbc.Row(
[
dbc.Col(
[dbc.NavbarBrand("Dashboard", className="ms-2")],
width={"size": "auto"},
),
],
align="center",
className="g-0",
),
dbc.Row(
[
dbc.Col(
[
dbc.Nav(
[
dbc.NavItem(
dbc.NavLink(
[
html.Div(
page["name"], className="ms-2"
),
],
href=page["path"],
active="exact",
),
)
for page in dash.page_registry.values()
],
navbar=True,
horizontal=True,
)
],
width={"size": "auto"},
)
],
align="center",
className="g-0",
),
],
fluid=True,
),
color="#041E42",
dark=True,
)
dash_app.layout = dbc.Container(
[
dcc.Interval(id="timer", interval=1000 * 1800, n_intervals=0),
dcc.Store(id="store-data", data=[], storage_type="session"),
dbc.Row(
[
dbc.Col([navbar], xs=8, sm=8, md=12, lg=12, xl=12, xxl=12),
]
),
html.Hr(),
dbc.Row(
[dbc.Col([dash.page_container], xs=8, sm=8, md=12, lg=12, xl=12, xxl=12)]
),
],
fluid=True,
)
if __name__ == "__main__":
dash_app.run_server(debug=True)
Appreciate your help