I’d like to use dark mode on the dash, I’ve been trying for two days but can’t find a solution. I don’t want a toggle button or any switch, I just simply want a dark theme. I’ve tried every solution I found on the internet, the background color changes, but the graph does not. This is a part of my code:
Hi @mocsar , I don’t think dbc themes can affect to graph background. So I think you should set template for your figure as plotly_dark or use plot_bgcolor='#000000',paper_bgcolor='#000000' when update layout.
If you don’t want a theme switch, you don’t need to update the figure in a callback or set the template.
Try running this this example
from dash import Dash, dcc, html
import plotly.express as px
import dash_bootstrap_components as dbc
from dash_bootstrap_templates import load_figure_template
# loads the "darkly" template and sets it as the default
load_figure_template("darkly")
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="size")
app=Dash(__name__, external_stylesheets=[dbc.themes.DARKLY])
app.layout = dbc.Container([
html.H1("Dash App in Dark Mode", className="text-center"),
dcc.Graph(figure=fig)
])
if __name__ == "__main__":
app.run(debug=True)
Plus you can make it even simpler if you just want to use the built-in plotly_dark template. Then you don’t need to use the Bootstrap themed templates from the dash_bootstrap_templates library. Then it’s not even one line of code different - it’s only changing one prop:
from dash import Dash, dcc, html
import plotly.express as px
import dash_bootstrap_components as dbc
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", color="size", template="plotly_dark")
app=Dash(__name__, external_stylesheets=[dbc.themes.DARKLY])
app.layout = dbc.Container([
html.H1("Dash App in Dark Mode", className="text-center"),
dcc.Graph(figure=fig)
])
if __name__ == "__main__":
app.run(debug=True)