Hello @Mmmwhy,
Made a couple of changes:
import dash
from dash_iconify import DashIconify
from dash import html, Output, Input, State, dcc
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
import plotly.express as px
app = dash.Dash(__name__, #external_stylesheets=[dbc.themes.BOOTSTRAP]
)
def get_icon(icon):
return DashIconify(icon=icon, height=16, color="#c2c7d0")
def create_nav_link(label, href):
return dmc.NavLink(
label=label,
href=href,
style={'display': 'inline-block'},
)
data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')
app.layout = dmc.MantineProvider(
theme={
"fontFamily": '"Inter", sans-serif',
"components": {
"NavLink": {"styles": {"label": {"color": "#c2c7d0"}}}
},
},
children=[
dmc.Container([
dmc.Navbar(
p="md",
fixed=False,
width={"base": 300},
hidden=True,
hiddenBreakpoint="md",
position="right",
height="100vh",
id="sidebar",
children=[
html.Div(
[
dmc.NavLink(
label="HOME",
icon=get_icon(icon="tabler:settings-2bi:house-door-fill"),
href="/",
),
dmc.NavLink(
label="kkk",
icon=get_icon(icon="tabler:fingerprint"),
childrenOffset=28,
opened=False,
children=[
dmc.NavLink(label="P"),
dmc.NavLink(label="A"),
dmc.NavLink(label="V"),
],
),
dmc.NavLink(
label="Gggg",
icon=get_icon(icon="tabler:fingerprint"),
childrenOffset=28,
opened=False,
children=[
dmc.NavLink(label="P"),
dmc.NavLink(label="A"),
dmc.NavLink(label="V"),
],
),
dmc.NavLink(
label="NOT WORKING",
icon=get_icon(icon="bi:house-door-fill"),
childrenOffset=28,
opened=False,
children=[
create_nav_link(
label=page["name"], href=page["path"]
)
for page in dash.page_registry.values()
if page["path"].startswith("/chapter3")
],
),
dmc.NavLink(
label="KKsdang",
icon=get_icon(icon="tabler:fingerprint"),
childrenOffset=28,
opened=False,
children=[
dmc.NavLink(label="P"),
dmc.NavLink(label="A"),
dmc.NavLink(label="V"),
],
),
],
style={"white-space": "nowrap"},
)
],
style={
"overflow": "hidden",
"transition": "width 0.3s ease-in-out",
"background-color": "#343a40",
},
),
dmc.Drawer(
title="Company Name",
id="drawer-simple",
padding="md",
zIndex=10000,
size=300,
overlayOpacity=0.1,
children=[],
style={'background-color': ''}, styles={'drawer': {'background-color': '#343a40'}}
),
dmc.Container(
[
dmc.Header(
height=60,
children=[
dmc.Group(
[
dmc.MediaQuery(
[
dmc.Button(
DashIconify(
icon="ci:hamburger-lg",
width=24,
height=24,
color="#c2c7d0",
),
variant="subtle",
p=1,
id="sidebar-button",
)
],
smallerThan="md",
styles={"display": "none"},
),
dmc.MediaQuery(
[
dmc.Button(
DashIconify(
icon="ci:hamburger-lg",
width=24,
height=24,
color="#c2c7d0",
),
variant="subtle",
p=1,
id="drawer-demo-button",
)
],
largerThan="md",
styles={"display": "none"},
),
dmc.Text("Company Name"),
]
)
],
p="10px",
style={"backgroundColor": "#fff"},
),
dmc.Container(
[
html.Div(dbc.Container(dcc.Graph(figure=fig), fluid=True)),
html.Div(dbc.Container(dcc.Graph(figure=fig), fluid=True)),
html.Div(dbc.Container(dcc.Graph(figure=fig), fluid=True)),
html.Div(dbc.Container(dcc.Graph(figure=fig), fluid=True)),
],
id="page-container",
p=0,
fluid=True,
style={
"background-color": "#f4f6f9",
"width": "100%",
"margin": "0",
"maxWidth": "100%", "overflow": "auto", 'flexShrink': '1', "maxHeight": "100%"
},
),
],
size="100%",
p=0,
m=0,
style={"display": "flex", "maxWidth": "100vw", "overflow": "hidden",
"flexGrow": "1", "maxHeight": "100%", "flexDirection": "column"},
id="content-container"
),
], size="100%",
p=0,
m=0,
style={"display": "flex", "maxWidth": "100vw", "overflow": "hidden", "maxHeight": "100vh",
"position": "absolute", "top": 0, "left": 0, "width": "100vw"},
id="overall-container"),],
)
@app.callback(
Output("sidebar", "width"),
Input("sidebar-button", "n_clicks"),
State("sidebar", "width"),
prevent_initial_call=True,
)
def drawer_demo(n, width):
if n:
if width["base"] == 300:
return {"base": 70}
else:
return {"base": 300}
else:
raise dash.exceptions.PreventUpdate
@app.callback(
Output("drawer-simple", "opened"),
Input("drawer-demo-button", "n_clicks"),
prevent_initial_call=True,
)
def drawer_dem(n_clicks):
return True
if __name__ == "__main__":
app.run_server(debug=True)
The navbar should stay put, while the content on the right is able to scroll.