dcc.Checklist

dcc.Checklist is a component for rendering a set of checkboxes.
See also RadioItems for selecting a single
option at a time or Dropdown for a more compact view.

Examples

Find a few usage examples below.

For more examples of minimal Dash apps that use dcc.Checklist, go to the community-driven Example Index.

Basic Checklist

To create a basic checklist, provide options and a value to dcc.Checklist in that order.

from dash import dcc

dcc.Checklist(
    ['New York City', 'Montréal', 'San Francisco'],
    ['New York City', 'Montréal']
)

Horizontal Options

Option labels render vertically in the browser by default. Add inline=True for them to be displayed horizontally.

from dash import dcc

dcc.Checklist(
    ['New York City', 'Montréal', 'San Francisco'],
    ['New York City', 'Montréal'],
    inline=True
)

inline=True, we configured the checklist options to be displayed horizontally.
This property is a shorthand for setting it on the labelStyle property and is available from Dash 2.1.
The same can be done with labelStyle={'display': 'inline-block'} in earlier versions of Dash.

Options and Value

The options and value properties are the first two arguments of dcc.Checklist. There are multiple ways to set options. The following examples define the same checklist:

dcc.Checklist(['New York City', 'Montreal', 'San Francisco'], ['Montreal'])
dcc.Checklist(
   options=['New York City', 'Montreal', 'San Francisco'],
   value=['Montreal']
)
dcc.Checklist(
   options=[
       {'label': 'New York City', 'value': 'New York City'},
       {'label': 'Montreal', 'value': 'Montreal'},
       {'label': 'San Francisco', 'value': 'San Francisco'},
   ],
   value=['Montreal']
)
dcc.Checklist(
   options={
        'New York City': 'New York City',
        'Montreal': 'Montreal',
        'San Francisco': 'San Francisco'
   },
   value=['Montreal']
)

In these examples, the option’s label (what the user sees) and the value (what’s passed into the callback) are equivalent. Often it is helpful for these to be separate so that you can easily change the label without changing the callback logic that uses the value:

dcc.Checklist(
   options=[
       {'label': 'New York City', 'value': 'NYC'},
       {'label': 'Montreal', 'value': 'MTL'},
       {'label': 'San Francisco', 'value': 'SF'},
   ],
   value=['MTL']
)
dcc.Checklist(
   options={
        'NYC': 'New York City',
        'MTL': 'Montreal',
        'SF': 'San Francisco'
   },
   value=['MTL']
)

Note: Versions of Dash before 2.1 only support keyword arguments for options and value, and also options must be provided as a list of dictionaries.

Flexible Data Types

We’ve seen how options on a checklist can be set using a list, a dictionary, or a list of dictionaries. options also accepts Pandas and NumPy data structures.

In this example, we use the DataFrame’s columns (df.columns) as the checklist options.

from dash import dcc
import pandas as pd
from plotly.express import data

df =  data.medals_long()

dcc.Checklist(df.columns, df.columns[0:2].values)

Here, we set options with df.nation.unique(). This Pandas method returns unique values in the ‘nation’ column. By passing it to options, our checklist displays all unique values in that column.

from dash import dcc
import pandas as pd
from plotly.express import data

df =  data.medals_long()

dcc.Checklist(df.nation.unique(), df.nation.unique()[0:2])

Components as Option Labels

This feature is available in Dash 2.5 and later.

In previous examples, we’ve set option labels as strings. You can also use Dash components as option labels.
In this example, each label is an html.Div component with an html.Img and text nested inside it.

from dash import dcc, html

dcc.Checklist(
    [
        {
            "label": html.Div(
                [
                    html.Img(src="/assets/images/language_icons/python_50px.svg"),
                    html.Div("Python", style={'font-size': 15, 'padding-left': 10}),
                ], style={'display': 'flex', 'align-items': 'center', 'justify-content': 'center'}
            ),
            "value": "Python",
        },
        {
            "label": html.Div(
                [
                    html.Img(src="/assets/images/language_icons/julia_50px.svg"),
                    html.Div("Julia", style={'font-size': 15, 'padding-left': 10}),
                ], style={'display': 'flex', 'align-items': 'center', 'justify-content': 'center'}
            ),
            "value": "Julia",
        },
        {
            "label": html.Div(
                [
                    html.Img(src="/assets/images/language_icons/r-lang_50px.svg"),
                    html.Div("R", style={'font-size': 15, 'padding-left': 10}),
                ], style={'display': 'flex', 'align-items': 'center', 'justify-content': 'center'}
            ),
            "value": "R",
        },
    ]
)

Styling Components as Option Labels

This feature is available in Dash 2.5 and later.

You can also style labels by using an html.Div component for each label and then setting styles using the style property:

from dash import dcc, html

dcc.Checklist(
    [
        {
            "label": html.Div(['Montreal'], style={'color': 'Gold', 'font-size': 20}),
            "value": "Montreal",
        },
        {
            "label": html.Div(['NYC'], style={'color': 'MediumTurqoise', 'font-size': 20}),
            "value": "NYC",
        },
        {
            "label": html.Div(['London'], style={'color': 'LightGreen', 'font-size': 20}),
            "value": "London",
        },
    ], value=['Montreal']
)

Checklist Properties

Access this documentation in your Python terminal with:
```python

help(dash.dcc.Checklist)
```

Our recommended IDE for writing Dash apps is Dash Enterprise’s
Data Science Workspaces,
which has typeahead support for Dash Component Properties.
Find out if your company is using
Dash Enterprise
.

options (list of dicts; optional):
An array of options.

options is a list of strings | numbers | booleans | dict | list of
dicts with keys:

value (list of strings | numbers | booleans; optional):
The currently selected value.

inline (boolean; default False):
Indicates whether labelStyle should be inline or not True:
Automatically set { ‘display’: ‘inline-block’ } to labelStyle False:
No additional styles are passed into labelStyle.

className (string; optional):
The class of the container (div).

style (dict; optional):
The style of the container (div).

inputStyle (dict; optional):
The style of the <input> checkbox element.

inputClassName (string; default ''):
The class of the <input> checkbox element.

labelStyle (dict; optional):
The style of the <label> that wraps the checkbox input and the
option’s label.

labelClassName (string; default ''):
The class of the <label> that wraps the checkbox input and the
option’s label.

id (string; optional):
The ID of this component, used to identify dash components in
callbacks. The ID needs to be unique across all of the components in
an app.

loading_state (dict; optional):
Object that holds the loading state object coming from dash-renderer.

loading_state is a dict with keys:

persistence (boolean | string | number; optional):
Used to allow user interactions in this component to be persisted when
the component - or the page - is refreshed. If persisted is truthy
and hasn’t changed from its previous value, a value that the user
has changed while using the app will keep that change, as long as the
new value also matches what was given originally. Used in
conjunction with persistence_type.

persisted_props (list of values equal to: ‘value’; default ['value']):
Properties whose user interactions will persist after refreshing the
component or the page. Since only value is allowed this prop can
normally be ignored.

persistence_type (a value equal to: ‘local’, ‘session’ or ‘memory’; default 'local'):
Where persisted user changes will be stored: memory: only kept in
memory, reset on page refresh. local: window.localStorage, data is
kept after the browser quit. session: window.sessionStorage, data is
cleared once the browser quit.