DCC.Checklist.checklist

DCC.Checklist.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.

Basic Checklist

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

open Dash.NET
open Dash.NET.Giraffe
open Dash.NET.DCC

let layout =
    Checklist.checklist "checklist" [
        Checklist.Attr.options [
            ChecklistOption.init("New York City", "NYC")
            ChecklistOption.init("Montréal", "MTL")
            ChecklistOption.init("San Francisco", "SF")
        ]
        Checklist.Attr.value ["NYC"; "MTL"]
    ]


[<EntryPoint>]
let main argv =
    DashApp.initDefault()
    |> DashApp.withLayout layout
    |> DashApp.run argv (DashGiraffeConfig.initDefault "localhost")

Horizontal Options

Option labels render vertically in the browser by default. You can also set them to display horizontally:

open Dash.NET
open Dash.NET.Giraffe
open Dash.NET.DCC

let layout =
    Checklist.checklist "checklist" [
        Checklist.Attr.options [
            ChecklistOption.init("New York City", "NYC")
            ChecklistOption.init("Montréal", "MTL")
            ChecklistOption.init("San Francisco", "SF")
        ]
        Checklist.Attr.value ["NYC"; "MTL"]
        Checklist.Attr.style [ StyleProperty ("display", "inline-block") ]
    ]

[<EntryPoint>]
let main argv =
    DashApp.initDefault()
    |> DashApp.withLayout layout
    |> DashApp.run argv (DashGiraffeConfig.initDefault "localhost")

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 a list of components containing an html.Img and text in an html.Span.

This example has not been ported to F# yet - showing the Python version instead.

Visit the old docs site for F# at: https://community.plotly.com/c/dash/net/26

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"},
)

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:

This example has not been ported to F# yet - showing the Python version instead.

Visit the old docs site for F# at: https://community.plotly.com/c/dash/net/26

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"},
)

Checklist Properties

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 records; optional):
An array of options.

options is a list of strings | numbers | bools | record | list of
records with keys:

  • disabled (bool; optional):
    If true, this option is disabled and cannot be selected.

  • label (list of or a singular dash component, string or number; 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 | number | bool; required):
    The value of the option. This value corresponds to the items
    specified in the value property.

value (list of strings | numbers | 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 (record; optional):
The style of the container (div).

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

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

labelStyle (record; 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 (record; optional):
Object that holds the loading state object coming from dash-renderer.

loading_state is a record 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 | 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.