Dash Bootstrap Templates

raw JSON →
2.1.0 verified Sat May 09 auth: no python

Provides Plotly figure templates that match Bootstrap themes for Dash apps, enabling seamless theming and a built-in theme switch component (ThemeSwitchAIO). Current version 2.1.0 requires Plotly 6. Released monthly with minor features and fixes.

pip install dash-bootstrap-templates
error ModuleNotFoundError: No module named 'dash_bootstrap_templates'
cause Package not installed or installed in wrong environment.
fix
pip install dash-bootstrap-templates
error dash.exceptions.NoLayoutException: The layout was None at the time the app was started.
cause load_figure_template() called before app layout is defined, or missing template parameter in figure.
fix
Ensure load_figure_template() is called early, and pass template='bootstrap' or similar to Plotly figures.
breaking Version 2.0.0+ requires Plotly 6. Projects using Plotly 5 must pin to dash-bootstrap-templates==1.3.0.
fix pip install dash-bootstrap-templates==1.3.0 if you cannot upgrade Plotly.
deprecated The 'dbc_css' parameter in load_figure_template is deprecated and may be removed in future versions.
fix Do not pass dbc_css; the function auto-detects stylesheets.
gotcha ThemeSwitchAIO requires dash-bootstrap-components >=1.0.0 and the initial theme must be passed as a string (e.g., 'BOOTSTRAP'), not as an object.
fix Use dbc.themes.BOOTSTRAP (string) for the themes parameter.

Load the bootstrap template and apply it to a Plotly Express scatter plot.

import dash
from dash import dcc, html
from dash_bootstrap_templates import load_figure_template
import dash_bootstrap_components as dbc
import plotly.express as px

load_figure_template('bootstrap')
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
df = px.data.gapminder()
fig = px.scatter(df.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent", template='bootstrap')
app.layout = dbc.Container([dcc.Graph(figure=fig)])
if __name__ == '__main__':
    app.run(debug=True)