dash-bootstrap-templates


Namedash-bootstrap-templates JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/AnnMarieW/dash-bootstrap-templates
SummaryA collection of Plotly figure templates with a Bootstrap theme
upload_time2024-06-19 19:30:53
maintainerNone
docs_urlNone
authorAnnMarieW
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Dash Bootstrap Templates

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


`dash-bootstrap-templates` library provides: 

- **52 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](https://dash-bootstrap-components.opensource.faculty.ai/). These templates will automatically style your figures with Bootstrap theme colors and fonts.
  - As of V1.1 a dark mode is available for each theme.  This is ideal for use with the [Bootstrap Color Modes](https://getbootstrap.com/docs/5.3/customize/color-modes/) available as of Bootstrap 5.3.0


- **Two  [All-in-One](https://dash.plotly.com/all-in-one-components) components** to change themes in a Dash app.
  - `ThemeSwitchAIO` toggles between two themes.
  - `ThemeChangerAIO` select from multiple themes.
  
- **Examples of a Color Mode Switch** to toggle between a light and dark theme.


- **The dbc.css stylesheet** which styles Dash AG Grid, Dash Core Components and the Dash DataTable with a Bootstrap theme. 
   - [![](https://data.jsdelivr.com/v1/package/gh/AnnMarieW/dash-bootstrap-templates/badge?style=rounded)](https://www.jsdelivr.com/package/gh/AnnMarieW/dash-bootstrap-templates)



> **Usage Notes**:
>  - The `ThemeChangerAIO` component  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.
> 
>  - As of V1.0.8, the themes in the `ThemeSwitchAIO` component can be specified as a pathname or a URL.  This allows for working
> off-line and with custom stylesheets.
> 
> - The Bootstrap themed Plotly figure templates can be used with any Plotly figure.  It does not require Dash or
> the Dash Bootstrap Components library.

<br>
<br>


## Figure Template Quickstart
```python"
pip install dash-bootstrap-templates
```
> Learn more about Plotly figure templates and themes at: https://plotly.com/python/templates/
```python
"""
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](https://user-images.githubusercontent.com/72614349/143956424-9e172c03-139e-4126-bed5-b1800ad7e17a.png)
![image](https://user-images.githubusercontent.com/72614349/143956545-769a00f8-92a3-44aa-8718-bdbb32b2464e.png)
![image](https://user-images.githubusercontent.com/72614349/143956649-32b620c7-231a-4de6-ad3a-8fb0863da2a4.png)
![image](https://user-images.githubusercontent.com/72614349/143956713-7fdbed38-6799-472b-87ba-d863481c6525.png)



![figure_template2](https://user-images.githubusercontent.com/72614349/129459807-30c22ffe-7a8c-44b9-9555-6cfd50ec355b.png)

<br>
<br>

## dbc.css  stylesheet

The  `dash-ag-grid`, `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](https://github.com/AnnMarieW/dash-bootstrap-templates) library. This stylesheet defines the "dbc" class.

Adding `className="dbc dbc-ag-grid"` 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/dash-bootstrap-templates@V1.0.2/dbc.min.css")
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])

```


Add  `className="dbc dbc-ag-grid"` to the outer container of the app or a component like this:
```
app.layout = dbc.Container(
    [
        ...
    ],
    fluid=True,
    className="dbc dbc-ag-grid"
)
```

**That's it!** Simply adding `className="dbc dbc-ag-grid"` will make Dash AG Grid,  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/adding-themes/dcc-components


If you have suggestion for improvements or if you find a bug, please let us know on the [issue tracker](https://github.com/AnnMarieW/dash-bootstrap-templates/issues)

**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](https://dash.plotly.com/all-in-one-components) 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"`


<br>
<br>


## ThemeChangerAIO Quickstart
```python

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/dash-bootstrap-templates@V1.0.1/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](https://user-images.githubusercontent.com/72614349/141466834-6b02f478-cae8-4927-b05e-be0e98cb61df.gif)

---------
```python

```
Here is the same app, but using a the `ThemeSwitchAIO` component to toggle between two themes.
See the  [(code here)](https://github.com/AnnMarieW/dash-bootstrap-templates/blob/main/examples/demo_toggle.py).

It's also possible to change the icons.  See an example of using Bootstrap icons instead of the default FontAwesome
icons [here](https://github.com/AnnMarieW/dash-bootstrap-templates/blob/main/examples/demo_toggle_icons.py).

![theme_toggle](https://user-images.githubusercontent.com/72614349/141466191-13709102-a2fb-45b5-a984-383d3e6ab373.gif)



<br>
<br>


## Color Mode Switch
__Requires dash-bootstrap-components>=1.5.0__

This is the recommended way to switch between a light and a dark mode using  [Bootstrap Color modes](https://getbootstrap.com/docs/5.3/customize/color-modes/) 
available in Bootstrap 5.3.0.


![color-mode-templates](https://github.com/AnnMarieW/dash-bootstrap-templates/assets/72614349/86c56043-08e0-4b8a-a473-13e2ef89533a)




```python
from dash import Dash, html, dcc, Input, Output, clientside_callback, callback
import plotly.express as px
import dash_bootstrap_components as dbc

from dash_bootstrap_templates import load_figure_template
load_figure_template(["minty", "minty_dark"])


df = px.data.gapminder()

app = Dash(__name__, external_stylesheets=[dbc.themes.MINTY, dbc.icons.FONT_AWESOME])

color_mode_switch =  html.Span(
    [
        dbc.Label(className="fa fa-moon", html_for="switch"),
        dbc.Switch( id="switch", value=False, className="d-inline-block ms-1", persistence=True),
        dbc.Label(className="fa fa-sun", html_for="switch"),
    ]
)

app.layout = dbc.Container(
    [
        html.Div(["Bootstrap Light Dark Color Modes Demo"], className="bg-primary text-white h3 p-2"),
        color_mode_switch,
        dcc.Graph(id="graph", className="border"),
    ]

)

@callback(
    Output("graph", "figure"),
    Input("switch", "value"),
)
def update_figure_template(switch_on):
    template = "minty" if switch_on else "minty_dark"
    fig = px.scatter(
        df.query("year==2007"),
        x="gdpPercap",
        y="lifeExp",
        size="pop",
        color="continent",
        log_x=True,
        size_max=60,
        template=template,
    )
    return fig



clientside_callback(
    """
    (switchOn) => {
       switchOn
         ? document.documentElement.setAttribute('data-bs-theme', 'light')
         : document.documentElement.setAttribute('data-bs-theme', 'dark')
       return window.dash_clientside.no_update
    }
    """,
    Output("switch", "id"),
    Input("switch", "value"),
)


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

<br>
<br>

## Dash AG Grid with a Bootstrap theme

Here is an example of the theme change component to show different Bootstrap themes with Dash AG Grid:


See live demo https://hellodash.pythonanywhere.com/adding-themes/ag-grid

![ag-grid-dbc-theme](https://github.com/AnnMarieW/dash-bootstrap-templates/assets/72614349/10bd25fc-1e01-4ba9-ac38-d18a14d7ef4f)

<br>
<br>


## Background

[Dash Labs](https://community.plotly.com/t/introducing-dash-labs/52087) 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](https://plotly.com/python/templates/).

<br>
<br>


## Available Themes

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

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

templates_dark = ['bootstrap_dark', 'cerulean_dark', 'cosmo_dark', 'cyborg_dark', 'darkly_dark', 'flatly_dark', 'journal_dark', 'litera_dark', 'lumen_dark', 'lux_dark', 'materia_dark', 'minty_dark', 'morph_dark', 'pulse_dark', 'quartz_dark', 'sandstone_dark', 'simplex_dark', 'sketchy_dark', 'slate_dark', 'solar_dark', 'spacelab_dark', 'superhero_dark', 'united_dark', 'vapor_dark', 'yeti_dark', 'zephyr_dark']



Note in dark themes ["cyborg", "darkly", "slate", "solar", "superhero", "vapor"], there is not much difference in the figure templates in light or dark color modes.



## 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: `switch_props` A dictionary of properties passed into the dbc.Switch component.
- param: `themes` A list of two urls for the external stylesheets or pathnames to files.
- 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AnnMarieW/dash-bootstrap-templates",
    "name": "dash-bootstrap-templates",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "AnnMarieW",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/dd/f5/65f7310a2e05c653fec163b8573077fbb2c8d7e03eb5b79a4c4b8f02106c/dash_bootstrap_templates-1.2.0.tar.gz",
    "platform": null,
    "description": "# Dash Bootstrap Templates\n\n#### See these features live at : https://hellodash.pythonanywhere.com/theme_explorer\n\n\n`dash-bootstrap-templates` library provides: \n\n- **52 Bootstrap themed Plotly figure templates** \n  - You will find a Plotly template for each of the 26 Bootstrap/Bootswatch themes available in the [Dash Bootstrap Components Library](https://dash-bootstrap-components.opensource.faculty.ai/). These templates will automatically style your figures with Bootstrap theme colors and fonts.\n  - As of V1.1 a dark mode is available for each theme.  This is ideal for use with the [Bootstrap Color Modes](https://getbootstrap.com/docs/5.3/customize/color-modes/) available as of Bootstrap 5.3.0\n\n\n- **Two  [All-in-One](https://dash.plotly.com/all-in-one-components) components** to change themes in a Dash app.\n  - `ThemeSwitchAIO` toggles between two themes.\n  - `ThemeChangerAIO` select from multiple themes.\n  \n- **Examples of a Color Mode Switch** to toggle between a light and dark theme.\n\n\n- **The dbc.css stylesheet** which styles Dash AG Grid, Dash Core Components and the Dash DataTable with a Bootstrap theme. \n   - [![](https://data.jsdelivr.com/v1/package/gh/AnnMarieW/dash-bootstrap-templates/badge?style=rounded)](https://www.jsdelivr.com/package/gh/AnnMarieW/dash-bootstrap-templates)\n\n\n\n> **Usage Notes**:\n>  - The `ThemeChangerAIO` component  and the `dbc.css` stylesheet requires  Dash Bootstrap Components>=V1.0.0.  It will only\n> work with the themes included in Dash Bootstrap Components>=V1.0.0.\n> \n>  - As of V1.0.8, the themes in the `ThemeSwitchAIO` component can be specified as a pathname or a URL.  This allows for working\n> off-line and with custom stylesheets.\n> \n> - The Bootstrap themed Plotly figure templates can be used with any Plotly figure.  It does not require Dash or\n> the Dash Bootstrap Components library.\n\n<br>\n<br>\n\n\n## Figure Template Quickstart\n```python\"\npip install dash-bootstrap-templates\n```\n> Learn more about Plotly figure templates and themes at: https://plotly.com/python/templates/\n```python\n\"\"\"\nA sample of 8 of the 26 Bootstrap themed Plotly figure templates available\nin the dash-bootstrap-template library\n\n\"\"\"\nfrom dash import Dash, html, dcc\nimport dash_bootstrap_components as dbc\nfrom dash_bootstrap_templates import load_figure_template\nimport plotly.express as px\n\ndf = px.data.gapminder()\n\ntemplates = [\n    \"bootstrap\",\n    \"minty\",\n    \"pulse\",\n    \"flatly\",\n    \"quartz\",\n    \"cyborg\",\n    \"darkly\",\n    \"vapor\",\n]\n\nload_figure_template(templates)\n\nfigures = [\n    px.scatter(\n        df.query(\"year==2007\"),\n        x=\"gdpPercap\",\n        y=\"lifeExp\",\n        size=\"pop\",\n        color=\"continent\",\n        log_x=True,\n        size_max=60,\n        template=template,\n        title=\"Gapminder 2007: '%s' theme\" % template,\n    )\n    for template in templates\n]\n\napp = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])\n\napp.layout = dbc.Container([dcc.Graph(figure=fig, className=\"m-4\") for fig in figures])\n\nif __name__ == \"__main__\":\n    app.run_server(debug=True)\n```\n\n![image](https://user-images.githubusercontent.com/72614349/143956424-9e172c03-139e-4126-bed5-b1800ad7e17a.png)\n![image](https://user-images.githubusercontent.com/72614349/143956545-769a00f8-92a3-44aa-8718-bdbb32b2464e.png)\n![image](https://user-images.githubusercontent.com/72614349/143956649-32b620c7-231a-4de6-ad3a-8fb0863da2a4.png)\n![image](https://user-images.githubusercontent.com/72614349/143956713-7fdbed38-6799-472b-87ba-d863481c6525.png)\n\n\n\n![figure_template2](https://user-images.githubusercontent.com/72614349/129459807-30c22ffe-7a8c-44b9-9555-6cfd50ec355b.png)\n\n<br>\n<br>\n\n## dbc.css  stylesheet\n\nThe  `dash-ag-grid`, `dash-core-components`, the Dash `DataTable` and Plotly figures are not automatically styled with a Bootstrap theme.\nAn easy way to make your Dash components look better with a Bootstrap theme is to use the stylesheet from\n the [dash-bootstrap-templates](https://github.com/AnnMarieW/dash-bootstrap-templates) library. This stylesheet defines the \"dbc\" class.\n\nAdding `className=\"dbc dbc-ag-grid\"` minimally styles Dash components with your selected Bootstrap theme:\n- Makes the text readable in both light and dark themes.\n- Uses theme's font-family.\n- Changes the accent color to the theme's primary color\n\n\nYou can add the dbc class as an external stylesheet like this:\n```\ndbc_css = (\"https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates@V1.0.2/dbc.min.css\")\napp = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])\n\n```\n\n\nAdd  `className=\"dbc dbc-ag-grid\"` to the outer container of the app or a component like this:\n```\napp.layout = dbc.Container(\n    [\n        ...\n    ],\n    fluid=True,\n    className=\"dbc dbc-ag-grid\"\n)\n```\n\n**That's it!** Simply adding `className=\"dbc dbc-ag-grid\"` will make Dash AG Grid,  Dash Core Components and the DataTable look better with **ALL** themes included in the `dash-bootstrap-components` library.\n> See a live demo at: https://hellodash.pythonanywhere.com/adding-themes/dcc-components\n\n\nIf you have suggestion for improvements or if you find a bug, please let us know on the [issue tracker](https://github.com/AnnMarieW/dash-bootstrap-templates/issues)\n\n**Requires `dash-bootstrap-components>=V1.0.0`**\n\n\n\n\n## Theme Switcher Components\n\n> See a live demo at https://hellodash.pythonanywhere.com/theme_change_components\n\n`dash-bootstrap-templates` has two [All-in-One](https://dash.plotly.com/all-in-one-components) components to change themes. \nThe `ThemeSwitchAIO` is a switch with icons on the left and right, which is ideal for toggling between a light and a dark theme. \nThe `ThemeChangerAIO` has a button that opens an `dbc.Offcanvas` component which by default shows all the available themes.\n\nNote the All-in-One component switches the Bootstrap stylesheet for the app and sets the default Plotly figure template\nfor the theme, however, figures must be updated in a callback in order to render the figure with the new template.\nSee the callback below for an example.  The `template_from_url` is a helper function that returns the template name\nbased on the theme url.  For example `template_from_ur(dbc.themes.SLATE)` returns `\"slate\"`\n\n\n<br>\n<br>\n\n\n## ThemeChangerAIO Quickstart\n```python\n\nfrom dash import Dash, dcc, html, Input, Output\nimport pandas as pd\nimport plotly.express as px\nimport dash_bootstrap_components as dbc\nfrom dash_bootstrap_templates import ThemeChangerAIO, template_from_url\n\n\ndbc_css = (\n    \"https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates@V1.0.1/dbc.min.css\"\n)\napp = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc_css])\n\n\ndf = pd.DataFrame(\n    {\n        \"Fruit\": [\"Apples\", \"Oranges\", \"Bananas\", \"Apples\", \"Oranges\", \"Bananas\"],\n        \"Amount\": [4, 1, 2, 2, 4, 5],\n        \"City\": [\"SF\", \"SF\", \"SF\", \"Montreal\", \"Montreal\", \"Montreal\"],\n    }\n)\nheader = html.H4(\n    \"ThemeChangerAIO Demo\", className=\"bg-primary text-white p-4 mb-2 text-center\"\n)\nbuttons = html.Div(\n    [\n        dbc.Button(\"Primary\", color=\"primary\"),\n        dbc.Button(\"Secondary\", color=\"secondary\"),\n        dbc.Button(\"Success\", color=\"success\"),\n        dbc.Button(\"Warning\", color=\"warning\"),\n        dbc.Button(\"Danger\", color=\"danger\"),\n        dbc.Button(\"Info\", color=\"info\"),\n        dbc.Button(\"Light\", color=\"light\"),\n        dbc.Button(\"Dark\", color=\"dark\"),\n        dbc.Button(\"Link\", color=\"link\"),\n    ],\n    className=\"m-4\",\n)\ngraph = html.Div(dcc.Graph(id=\"graph\"), className=\"m-4\")\n\napp.layout = dbc.Container(\n    [\n        header,\n        dbc.Row(\n            [\n                dbc.Col(ThemeChangerAIO(aio_id=\"theme\", radio_props={\"value\":dbc.themes.FLATLY}), width=2,),\n                dbc.Col([buttons, graph],width=10),\n            ]\n        ),\n    ],\n    className=\"m-4 dbc\",\n    fluid=True,\n)\n\n\n@app.callback(\n    Output(\"graph\", \"figure\"), Input(ThemeChangerAIO.ids.radio(\"theme\"), \"value\"),\n)\ndef update_graph_theme(theme):\n    return px.bar(\n        df, x=\"Fruit\", y=\"Amount\", color=\"City\", barmode=\"group\", template=template_from_url(theme)\n    )\n\n\nif __name__ == \"__main__\":\n    app.run_server(debug=True)\n\n```\n\n![theme_changer](https://user-images.githubusercontent.com/72614349/141466834-6b02f478-cae8-4927-b05e-be0e98cb61df.gif)\n\n---------\n```python\n\n```\nHere is the same app, but using a the `ThemeSwitchAIO` component to toggle between two themes.\nSee the  [(code here)](https://github.com/AnnMarieW/dash-bootstrap-templates/blob/main/examples/demo_toggle.py).\n\nIt's also possible to change the icons.  See an example of using Bootstrap icons instead of the default FontAwesome\nicons [here](https://github.com/AnnMarieW/dash-bootstrap-templates/blob/main/examples/demo_toggle_icons.py).\n\n![theme_toggle](https://user-images.githubusercontent.com/72614349/141466191-13709102-a2fb-45b5-a984-383d3e6ab373.gif)\n\n\n\n<br>\n<br>\n\n\n## Color Mode Switch\n__Requires dash-bootstrap-components>=1.5.0__\n\nThis is the recommended way to switch between a light and a dark mode using  [Bootstrap Color modes](https://getbootstrap.com/docs/5.3/customize/color-modes/) \navailable in Bootstrap 5.3.0.\n\n\n![color-mode-templates](https://github.com/AnnMarieW/dash-bootstrap-templates/assets/72614349/86c56043-08e0-4b8a-a473-13e2ef89533a)\n\n\n\n\n```python\nfrom dash import Dash, html, dcc, Input, Output, clientside_callback, callback\nimport plotly.express as px\nimport dash_bootstrap_components as dbc\n\nfrom dash_bootstrap_templates import load_figure_template\nload_figure_template([\"minty\", \"minty_dark\"])\n\n\ndf = px.data.gapminder()\n\napp = Dash(__name__, external_stylesheets=[dbc.themes.MINTY, dbc.icons.FONT_AWESOME])\n\ncolor_mode_switch =  html.Span(\n    [\n        dbc.Label(className=\"fa fa-moon\", html_for=\"switch\"),\n        dbc.Switch( id=\"switch\", value=False, className=\"d-inline-block ms-1\", persistence=True),\n        dbc.Label(className=\"fa fa-sun\", html_for=\"switch\"),\n    ]\n)\n\napp.layout = dbc.Container(\n    [\n        html.Div([\"Bootstrap Light Dark Color Modes Demo\"], className=\"bg-primary text-white h3 p-2\"),\n        color_mode_switch,\n        dcc.Graph(id=\"graph\", className=\"border\"),\n    ]\n\n)\n\n@callback(\n    Output(\"graph\", \"figure\"),\n    Input(\"switch\", \"value\"),\n)\ndef update_figure_template(switch_on):\n    template = \"minty\" if switch_on else \"minty_dark\"\n    fig = px.scatter(\n        df.query(\"year==2007\"),\n        x=\"gdpPercap\",\n        y=\"lifeExp\",\n        size=\"pop\",\n        color=\"continent\",\n        log_x=True,\n        size_max=60,\n        template=template,\n    )\n    return fig\n\n\n\nclientside_callback(\n    \"\"\"\n    (switchOn) => {\n       switchOn\n         ? document.documentElement.setAttribute('data-bs-theme', 'light')\n         : document.documentElement.setAttribute('data-bs-theme', 'dark')\n       return window.dash_clientside.no_update\n    }\n    \"\"\",\n    Output(\"switch\", \"id\"),\n    Input(\"switch\", \"value\"),\n)\n\n\nif __name__ == \"__main__\":\n    app.run_server(debug=True)\n```\n\n<br>\n<br>\n\n## Dash AG Grid with a Bootstrap theme\n\nHere is an example of the theme change component to show different Bootstrap themes with Dash AG Grid:\n\n\nSee live demo https://hellodash.pythonanywhere.com/adding-themes/ag-grid\n\n![ag-grid-dbc-theme](https://github.com/AnnMarieW/dash-bootstrap-templates/assets/72614349/10bd25fc-1e01-4ba9-ac38-d18a14d7ef4f)\n\n<br>\n<br>\n\n\n## Background\n\n[Dash Labs](https://community.plotly.com/t/introducing-dash-labs/52087) is Plotly library that explores new features for future releases of Dash. \nIn Dash Labs V0.4.0, there was a cool feature where Bootstrap themed figure templates were created \"on the fly\". This was a\npart of the layout templates project that is no longer being developed.    \n\nEven though these Bootstrap themed figure templates will not be included in Dash, the `dash-bootstrap-templates` makes\nthem available to you. The figure templates are created using the Dash Labs' algorithms and saved in json format.  When \nyou 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 \ninformation about  Plotly figure templates [here](https://plotly.com/python/templates/).\n\n<br>\n<br>\n\n\n## Available Themes\n\nThis library provides a figure template for the following Bootstrap/Bootswatch themes:\n\ntemplates = [\n  \"bootstrap\",\n  \"cerulean\",\n  \"cosmo\",\n  \"cyborg\",\n  \"darkly\",\n  \"flatly\",\n  \"journal\",\n  \"litera\",\n  \"lumen\",\n  \"lux\",\n  \"materia\",\n  \"minty\",\n  \"morph\",\n  \"pulse\",\n  \"quartz\",\n  \"sandstone\",\n  \"simplex\",\n  \"sketchy\",\n  \"slate\",\n  \"solar\",\n  \"spacelab\",\n  \"superhero\",\n  \"united\",\n  \"vapor\",\n  \"yeti\",\n  \"zephyr\"\n]\n\ntemplates_dark = ['bootstrap_dark', 'cerulean_dark', 'cosmo_dark', 'cyborg_dark', 'darkly_dark', 'flatly_dark', 'journal_dark', 'litera_dark', 'lumen_dark', 'lux_dark', 'materia_dark', 'minty_dark', 'morph_dark', 'pulse_dark', 'quartz_dark', 'sandstone_dark', 'simplex_dark', 'sketchy_dark', 'slate_dark', 'solar_dark', 'spacelab_dark', 'superhero_dark', 'united_dark', 'vapor_dark', 'yeti_dark', 'zephyr_dark']\n\n\n\nNote in dark themes [\"cyborg\", \"darkly\", \"slate\", \"solar\", \"superhero\", \"vapor\"], there is not much difference in the figure templates in light or dark color modes.\n\n\n\n## ThemeChangerAIO Reference\n**ThemeChangerAIO** is an All-in-One component  composed  of a parent `html.Div` with\nthe following components as children:\n\n- `dbc.Button` (\"`switch`\") Opens the Offcanvas component for user to select a theme.\n- `dbc.Offcanvas` (\"`offcanvas`\")\n- `dbc.RadioItems` (\"`radio`\").  The themes are displayed as RadioItems inside the `dbc.Offcanvas` component.\n  The `value` is a url for the theme\n- `html.Div` is used as the `Output` of the clientside callbacks.\n\nThe ThemeChangerAIO component updates the stylesheet  when the `value` of radio changes. (ie the user selects a new theme)\n\n- param: `radio_props` A dictionary of properties passed into the dbc.RadioItems component. The default `value` is `dbc.themes.BOOTSTRAP`\n- param: `button_props`  A dictionary of properties passed into the dbc.Button component.\n- param: `offcanvas_props`. A dictionary of properties passed into the dbc.Offcanvas component\n- param: `aio_id` The All-in-One component ID used to generate components' dictionary IDs.\n\nThe All-in-One component dictionary IDs are available as:\n\n- ThemeChangerAIO.ids.radio(aio_id)\n- ThemeChangerAIO.ids.offcanvas(aio_id)\n- ThemeChangerAIO.ids.button(aio_id)\n    \n\n## ThemeSwitchAIO Reference\n\n**ThemeSwitchAIO** is an All-in-One component  composed  of a parent `html.Div` with the following components as children:\n\n- `dbc.Switch` (\"`switch`\") with icons to the left and right of the switch.\n- `dcc.Store` (\"`store`\") The `themes` are stored in the `data` prop.\n- `html.Div` is used as the `Output` of the clientside callbacks.\n\nThe ThemeSwitchAIO component updates the stylesheet when triggered by changes to the `value` of `switch` or when\nthe themes are updated in the \"`store`\" component.  The themes in the switch may be updated in a callback\nby changing the theme urls in the \"`store`\" component.\n\n- param: `switch_props` A dictionary of properties passed into the dbc.Switch component.\n- param: `themes` A list of two urls for the external stylesheets or pathnames to files.\n- param: `icons`  A dict of the icons to the left and right of the switch. The default is  \n  `{\"left\" :\"fa fa-moon\", \"right\" :\"fa fa-sun\"}`.\n- param: `aio_id` The All-in-One component ID used to generate component's dictionary IDs.\n\nThe All-in-One component dictionary IDs are available as\n- ThemeSwitchAIO.ids.switch(aio_id)\n- ThemeSwitchAIO.ids.store(aio_id)\n\n---\n\n### Contributors\nSpecial thanks to @tcbegley and @emilhe for their help with this project.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A collection of Plotly figure templates with a Bootstrap theme",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/AnnMarieW/dash-bootstrap-templates"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94274bc38848315a8182b0edbc6b560db02f93fe249f261d75e4fa4cc8291da0",
                "md5": "565b98f5cef2706d921e233a1870b157",
                "sha256": "450447bd068249fa8d1e9fdbd996de5ba28ff4d19a3073f5327d57f1401fd56f"
            },
            "downloads": -1,
            "filename": "dash_bootstrap_templates-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "565b98f5cef2706d921e233a1870b157",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 97199,
            "upload_time": "2024-06-19T19:30:51",
            "upload_time_iso_8601": "2024-06-19T19:30:51.724679Z",
            "url": "https://files.pythonhosted.org/packages/94/27/4bc38848315a8182b0edbc6b560db02f93fe249f261d75e4fa4cc8291da0/dash_bootstrap_templates-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ddf565f7310a2e05c653fec163b8573077fbb2c8d7e03eb5b79a4c4b8f02106c",
                "md5": "101390554c13c735408b857004b975af",
                "sha256": "666dff73f091e4544337004667ed4c486767a6344695d7cfb2974c660f03aa0e"
            },
            "downloads": -1,
            "filename": "dash_bootstrap_templates-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "101390554c13c735408b857004b975af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 110484,
            "upload_time": "2024-06-19T19:30:53",
            "upload_time_iso_8601": "2024-06-19T19:30:53.289083Z",
            "url": "https://files.pythonhosted.org/packages/dd/f5/65f7310a2e05c653fec163b8573077fbb2c8d7e03eb5b79a4c4b8f02106c/dash_bootstrap_templates-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-19 19:30:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AnnMarieW",
    "github_project": "dash-bootstrap-templates",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dash-bootstrap-templates"
}
        
Elapsed time: 0.35030s