Skip to content

Checklist with dictionary value #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mxlei01 opened this issue Jul 20, 2018 · 2 comments
Closed

Checklist with dictionary value #298

mxlei01 opened this issue Jul 20, 2018 · 2 comments

Comments

@mxlei01
Copy link

mxlei01 commented Jul 20, 2018

It seems that value with dictionary causes only one option to appear:

dcc.Checklist(
    id="account-ad-options",
    options=[
        {'label': 'Optimization', 'value': {"optimization": True}},
        {'label': 'Reports', 'value': {"reports": True}}
    ],
    values=[]
),

image

dcc.Checklist(
    id="account-ad-options",
    options=[
        {'label': 'Optimization', 'value': 'optimization'},
        {'label': 'Reports', 'value': 'reports'}
    ],
    values=[]
),

image

Dictionary as values could be pretty handy to control inputs going inside a function with ChainMap and passing the dictionary as variables into a function with ** (two star).

@chriddyp
Copy link
Member

chriddyp commented Aug 1, 2018

This isn't supported in our underlying component. Our documentation (https://dash.plot.ly/dash-core-components/dropdown) should do a better job of explaining these nested types but we also don't display any examples that use nested objects. We'll do a better job of raising errors for these types of issues when #264 is solved.

If you need to do this, create a separate dictionary:

values = {
     'optimization': {'key': 'value'}
}

dcc.Checklist(options=[{'label': 'Optimization', 'value': 'optimization'})

and refer to it in your callback:

more_data = values[value]  # {'key': 'value'}

@chriddyp chriddyp closed this as completed Aug 1, 2018
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 28, 2021
HammadTheOne pushed a commit that referenced this issue Jul 23, 2021
@LawrenceAD
Copy link

Below code will help to enable all the options by defualt :

default_options = [
{'label': 'Optimization', 'value': 'optimization'},
{'label': 'Reports', 'value': 'reports'}
]
dcc.Checklist(
id="account-ad-options",
options=default_options ,
value=[d["value"] for d in default_options]
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants