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.
Find a few usage examples below.
To create a basic checklist, provide options
and a value
to dcc_checklist
in that order.
using Dash
app = dash()
app.layout = dcc_checklist(
options = [
Dict("label" => "New York City", "value" => "NYC"),
Dict("label" => "Montreal", "value" => "MTL"),
Dict("label" => "San Francisco", "value" => "SF")
],
value = ["MTL", "SF"],
)
run_server(app, "0.0.0.0", debug=true)
Option labels render vertically in the browser by default. You can also set them to display horizontally:
using Dash
app = dash()
app.layout = dcc_checklist(
options = [
Dict("label" => "New York City", "value" => "NYC"),
Dict("label" => "Montreal", "value" => "MTL"),
Dict("label" => "San Francisco", "value" => "SF")
],
value = ["MTL", "SF"],
labelStyle = Dict("display" => "inline-block")
)
run_server(app, "0.0.0.0", debug=true)
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 a list of components containing an html.Img
and text in an html.Span
.
This example has not been ported to Julia yet - showing the Python version instead.
Visit the old docs site for Julia at: https://community.plotly.com/c/dash/julia/20
from dash import dcc, html
dcc.Checklist(
[
{
"label": [
html.Img(src="/assets/images/language_icons/python_50px.svg"),
html.Span("Python", style={"font-size": 15, "padding-left": 10}),
],
"value": "Python",
},
{
"label": [
html.Img(src="/assets/images/language_icons/julia_50px.svg"),
html.Span("Julia", style={"font-size": 15, "padding-left": 10}),
],
"value": "Julia",
},
{
"label": [
html.Img(src="/assets/images/language_icons/r-lang_50px.svg"),
html.Span("R", style={"font-size": 15, "padding-left": 10}),
],
"value": "R",
},
],
labelStyle={"display": "flex", "align-items": "center"},
)
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:
This example has not been ported to Julia yet - showing the Python version instead.
Visit the old docs site for Julia at: https://community.plotly.com/c/dash/julia/20
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'],
labelStyle={"display": "flex", "align-items": "center"},
)
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
(Array of Dicts; optional):
An array of options.
options
is an Array of Strings | Reals | Bools | Dict | Array of
Dicts with keys:
disabled
(Bool; optional):
If true, this option is disabled and cannot be selected.
label
(Array of or a singular dash component, String or Real; required):
The option’s label.
title
(String; optional):
The HTML ‘title’ attribute for the option. Allows for information
on hover. For more information on this attribute, see
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title.
value
(String | Real | Bool; required):
The value of the option. This value corresponds to the items
specified in the value
property.
value
(Array of Strings | Reals | Bools; optional):
The currently selected value.
inline
(Bool; default false
):
Indicates whether the options labels should be displayed inline
(true=horizontal) or in a block (false=vertical).
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:
component_name
(String; optional):
Holds the name of the component that is loading.
is_loading
(Bool; optional):
Determines if the component is loading or not.
prop_name
(String; optional):
Holds which property is loading.
persistence
(Bool | String | Real; 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
(Array 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.