from dash import Dash, dcc, html, clientside_callback, Input, Output
import dash_bootstrap_components as dbc
app = Dash(__name__, external_stylesheets=[dbc.themes.MINTY ])
title = html.H3("dcc.Sliders with a Boostrap theme")
sliders = html.Div(
[
dcc.RangeSlider(0, 20, value=[5, 15], className="my-2"),
dcc.Slider(min=0, max=20, step=5, value=10, className="mb-2"),
dcc.Slider(
min=0,
max=10,
step=1,
value=5,
marks=None,
tooltip={"placement": "bottom", "always_visible": True},
),
],
# className="dbc"
)
color_mode_switch = html.Span(
[
dbc.Label(className="fa fa-moon", html_for="switch"),
dbc.Switch( id="switch", value=True, className="d-inline-block ms-1", persistence=True),
dbc.Label(className="fa fa-sun", html_for="switch"),
]
)
app.layout = dbc.Container([title, color_mode_switch, sliders])
clientside_callback(
"""
(switchOn) => {
document.documentElement.setAttribute('data-bs-theme', switchOn ? 'light' : 'dark');
return window.dash_clientside.no_update
}
""",
Output("switch", "id"),
Input("switch", "value"),
)
if __name__ == "__main__":
app.run_server(debug=True)