All Projects → AnnMarieW → dash-bootstrap-templates

AnnMarieW / dash-bootstrap-templates

Licence: MIT license
A collection of 26 Plotly figure templates with a Bootstrap theme. Two theme switch components. Stylesheet to apply Bootstrap themes to Plotly Dash components.

Programming Languages

python
139335 projects - #7 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to dash-bootstrap-templates

Dtale
Visualizer for pandas data structures
Stars: ✭ 2,864 (+10128.57%)
Mutual labels:  plotly-dash
2019-nCoV-dash
新型冠状病毒(2019-nCoV)肺炎(COVID-19)疫情展示
Stars: ✭ 13 (-53.57%)
Mutual labels:  plotly-dash
dash-daq
Control components for Dash
Stars: ✭ 132 (+371.43%)
Mutual labels:  plotly-dash
Slapdash
Boilerplate for bootstrapping scalable multi-page Dash applications
Stars: ✭ 225 (+703.57%)
Mutual labels:  plotly-dash
Interactive-Dashboards-and-Data-Apps-with-Plotly-and-Dash
Interactive Dashboards and Data Apps with Plotly and Dash, published by Packt
Stars: ✭ 181 (+546.43%)
Mutual labels:  plotly-dash
dash-editor-components
Simple Python Code Editor in Dash 📜
Stars: ✭ 38 (+35.71%)
Mutual labels:  plotly-dash
Dash Component Boilerplate
Get started creating your own Dash components here.
Stars: ✭ 149 (+432.14%)
Mutual labels:  plotly-dash
dash-redis-celery-periodic-updates
Demo apps now maintained in https://github.com/plotly/dash-enterprise-docs
Stars: ✭ 47 (+67.86%)
Mutual labels:  plotly-dash
covid-19
Coronavirus COVID-19 Dashboard - Global Kaggle Data
Stars: ✭ 31 (+10.71%)
Mutual labels:  plotly-dash
ai-lab
Artificial Intelligence & Machine Learning Experiments by DevScope
Stars: ✭ 19 (-32.14%)
Mutual labels:  plotly-dash
Dash
Analytical Web Apps for Python, R, Julia, and Jupyter. No JavaScript Required.
Stars: ✭ 15,592 (+55585.71%)
Mutual labels:  plotly-dash
Dash.jl
Dash for Julia - A Julia interface to the Dash ecosystem for creating analytic web applications in Julia. No JavaScript required.
Stars: ✭ 248 (+785.71%)
Mutual labels:  plotly-dash
dash-mantine-components
Plotly Dash components based on Mantine React Components
Stars: ✭ 263 (+839.29%)
Mutual labels:  plotly-dash
Plotly.js
Open-source JavaScript charting library behind Plotly and Dash
Stars: ✭ 14,268 (+50857.14%)
Mutual labels:  plotly-dash
dash-lollapalooza-brasil-2018
🎟Using Plotly to visualize data from Lollapalooza
Stars: ✭ 23 (-17.86%)
Mutual labels:  plotly-dash
Dash Detr
A User Interface for DETR built with Dash. 100% Python.
Stars: ✭ 154 (+450%)
Mutual labels:  plotly-dash
gaitutils
Extract and visualize gait data
Stars: ✭ 28 (+0%)
Mutual labels:  plotly-dash
trending-twitter
Simple dashboard for getting currently trending hashtags and topics on Twitter
Stars: ✭ 23 (-17.86%)
Mutual labels:  plotly-dash
feffery-antd-components
Dash + Antd = 😍
Stars: ✭ 97 (+246.43%)
Mutual labels:  plotly-dash
market-monitor
Interactive app to monitor market using Python
Stars: ✭ 20 (-28.57%)
Mutual labels:  plotly-dash

Dash Bootstrap Templates

See these features live at : https://hellodash.pythonanywhere.com/theme_explorer

dash-bootstrap-templates library provides:

  • Bootstrap themed Plotly figure templates. You will find a Plotly template for each of the 26 Bootstrap/Bootswatch themes available in the Dash Bootstrap Components Library. These templates will automatically style your figures with Bootstrap theme colors and fonts.

  • Two All-in-One components to change themes in a Dash app.

    • ThemeSwitchAIO toggles between two themes.
    • ThemeChangerAIO select from multiple themes.
  • The dbc.css stylesheet which styles Dash Core Components and the Dash DataTable with a Bootstrap theme.

Note: The ThemeSwitchAIO and ThemeChangerAIO components and the dbc.css stylesheet requires Dash Bootstrap Components>=V1.0.0. It will only work with the themes included in Dash Bootstrap Components>=V1.0.0.

Figure Template Quickstart

pip install dash-bootstrap-templates

Learn more about Plotly figure templates and themes at: https://plotly.com/python/templates/

"""
A sample of 8 of the 26 Bootstrap themed Plotly figure templates available
in the dash-bootstrap-template library

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

df = px.data.gapminder()

templates = [
    "bootstrap",
    "minty",
    "pulse",
    "flatly",
    "quartz",
    "cyborg",
    "darkly",
    "vapor",
]

load_figure_template(templates)

figures = [
    px.scatter(
        df.query("year==2007"),
        x="gdpPercap",
        y="lifeExp",
        size="pop",
        color="continent",
        log_x=True,
        size_max=60,
        template=template,
        title="Gapminder 2007: '%s' theme" % template,
    )
    for template in templates
]

app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container([dcc.Graph(figure=fig, className="m-4") for fig in figures])

if __name__ == "__main__":
    app.run_server(debug=True)

image image image image

figure_template2

dbc.css stylesheet

The dash-core-components, the Dash DataTable and Plotly figures are not automatically styled with a Bootstrap theme. An easy way to make your Dash components look better with a Bootstrap theme is to use the stylesheet from the dash-bootstrap-templates library. This stylesheet defines the "dbc" class.

Adding className="dbc" minimally styles Dash components with your selected Bootstrap theme:

  • Makes the text readable in both light and dark themes.
  • Uses theme's font-family.
  • Changes the accent color to the theme's primary color

You can add the dbc class as an external stylesheet like this:

dbc_css = ("https://cdn.jsdelivr.net/gh/AnnMarieW/[email protected]/dbc.min.css")
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])

Add className="dbc" to the outer container of the app or a component like this:

app.layout = dbc.Container(
    [
        ...
    ],
    fluid=True,
    className="dbc"
)

That's it! Simply adding className="dbc" will make Dash Core Components and the DataTable look better with ALL themes included in the dash-bootstrap-components library.

See a live demo at: https://hellodash.pythonanywhere.com/about_dbc_css

If you have suggestion for improvements or if you find a bug, please let us know on the issue tracker

Requires dash-bootstrap-components>=V1.0.0

Theme Switcher Components

See a live demo at https://hellodash.pythonanywhere.com/theme_change_components

dash-bootstrap-templates has two All-in-One components to change themes. The ThemeSwitchAIO is a switch with icons on the left and right, which is ideal for toggling between a light and a dark theme. The ThemeChangerAIO has a button that opens an dbc.Offcanvas component which by default shows all the available themes.

Note the All-in-One component switches the Bootstrap stylesheet for the app and sets the default Plotly figure template for the theme, however, figures must be updated in a callback in order to render the figure with the new template. See the callback below for an example. The template_from_url is a helper function that returns the template name based on the theme url. For example template_from_ur(dbc.themes.SLATE) returns "slate"

ThemeChangerAIO Quickstart

from dash import Dash, dcc, html, Input, Output
import pandas as pd
import plotly.express as px
import dash_bootstrap_components as dbc
from dash_bootstrap_templates import ThemeChangerAIO, template_from_url


dbc_css = (
    "https://cdn.jsdelivr.net/gh/AnnMarieW/[email protected]/dbc.min.css"
)
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])


df = pd.DataFrame(
    {
        "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
        "Amount": [4, 1, 2, 2, 4, 5],
        "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"],
    }
)
header = html.H4(
    "ThemeChangerAIO Demo", className="bg-primary text-white p-4 mb-2 text-center"
)
buttons = html.Div(
    [
        dbc.Button("Primary", color="primary"),
        dbc.Button("Secondary", color="secondary"),
        dbc.Button("Success", color="success"),
        dbc.Button("Warning", color="warning"),
        dbc.Button("Danger", color="danger"),
        dbc.Button("Info", color="info"),
        dbc.Button("Light", color="light"),
        dbc.Button("Dark", color="dark"),
        dbc.Button("Link", color="link"),
    ],
    className="m-4",
)
graph = html.Div(dcc.Graph(id="graph"), className="m-4")

app.layout = dbc.Container(
    [
        header,
        dbc.Row(
            [
                dbc.Col(ThemeChangerAIO(aio_id="theme", radio_props={"value":dbc.themes.FLATLY}), width=2,),
                dbc.Col([buttons, graph],width=10),
            ]
        ),
    ],
    className="m-4 dbc",
    fluid=True,
)


@app.callback(
    Output("graph", "figure"), Input(ThemeChangerAIO.ids.radio("theme"), "value"),
)
def update_graph_theme(theme):
    return px.bar(
        df, x="Fruit", y="Amount", color="City", barmode="group", template=template_from_url(theme)
    )


if __name__ == "__main__":
    app.run_server(debug=True)

theme_changer


Here is the same app, but using a the ThemeSwitchAIO component to toggle between two themes. See the (code here).

It's also possible to change the icons. See an example of using Bootstrap icons instead of the default FontAwesome icons here.

theme_toggle

Background

Dash Labs is Plotly library that explores new features for future releases of Dash. In Dash Labs V0.4.0, there was a cool feature where Bootstrap themed figure templates were created "on the fly". This was a part of the layout templates project that is no longer being developed.

Even though these Bootstrap themed figure templates will not be included in Dash, the dash-bootstrap-templates makes them available to you. The figure templates are created using the Dash Labs' algorithms and saved in json format. When you use load_figure_template() in your app, it loads the json file, adds it to plotly.io and sets it as the default figure template for an app. See more information about Plotly figure templates here.

Available Themes

This library provides a figure template for the following Bootstrap/Bootswatch themes:

valid_themes = [ "bootstrap", "cerulean", "cosmo", "flatly", "journal", "litera", "lumen", "lux", "materia", "minty", "pulse", "sandstone", "simplex", "sketchy", "spacelab", "united", "yeti", "cyborg", "darkly", "slate", "solar", "superhero", "morph", "quartz", "vapor" "zephyr" ]

ThemeChangerAIO Reference

ThemeChangerAIO is an All-in-One component composed of a parent html.Div with the following components as children:

  • dbc.Button ("switch") Opens the Offcanvas component for user to select a theme.
  • dbc.Offcanvas ("offcanvas")
  • dbc.RadioItems ("radio"). The themes are displayed as RadioItems inside the dbc.Offcanvas component. The value is a url for the theme
  • html.Div is used as the Output of the clientside callbacks.

The ThemeChangerAIO component updates the stylesheet when the value of radio changes. (ie the user selects a new theme)

  • param: radio_props A dictionary of properties passed into the dbc.RadioItems component. The default value is dbc.themes.BOOTSTRAP
  • param: button_props A dictionary of properties passed into the dbc.Button component.
  • param: offcanvas_props. A dictionary of properties passed into the dbc.Offcanvas component
  • param: aio_id The All-in-One component ID used to generate components' dictionary IDs.

The All-in-One component dictionary IDs are available as:

  • ThemeChangerAIO.ids.radio(aio_id)
  • ThemeChangerAIO.ids.offcanvas(aio_id)
  • ThemeChangerAIO.ids.button(aio_id)

ThemeSwitchAIO Reference

ThemeSwitchAIO is an All-in-One component composed of a parent html.Div with the following components as children:

  • dbc.Switch ("switch") with icons to the left and right of the switch.
  • dcc.Store ("store") The themes are stored in the data prop.
  • html.Div is used as the Output of the clientside callbacks.

The ThemeSwitchAIO component updates the stylesheet when triggered by changes to the value of switch or when the themes are updated in the "store" component. The themes in the switch may be updated in a callback by changing the theme urls in the "store" component.

  • param: themes A list of two urls for the external stylesheets. The default is [dbc.themes.CYBORG, dbc.themes.BOOTSTRAP].
  • param: icons A dict of the icons to the left and right of the switch. The default is
    {"left" :"fa fa-moon", "right" :"fa fa-sun"}.
  • param: aio_id The All-in-One component ID used to generate component's dictionary IDs.

The All-in-One component dictionary IDs are available as

  • ThemeSwitchAIO.ids.switch(aio_id)
  • ThemeSwitchAIO.ids.store(aio_id)

Contributors

Special thanks to @tcbegley and @emilhe for their help with this project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].