Checklist example doesn't work Dash 2.0

I’m trying to use examples from the documentation but the examples no longer work without extensive component definition. In checklist documentation this is given as the first exapmle:

dcc.Checklist(['New York City', 'Montreal', 'San Francisco'], 'Montreal')

But results in

Exception has occurred: TypeError
`id` prop must be a string or dict, not ['New York City', 'Montreal', 'San Francisco']

Even if I define the component attributes:

checklist1 = dcc.Checklist(id="checklist1", options=['New York City', 'Montreal', 'San Francisco'], value='Montreal')

I don’t see the options listed in my app:
Screenshot from 2022-03-09 08-06-07

However, this code works fine:

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

So to use a valid checklist requires manually defining the label and value of each entry which is tedious and harder when I’m trying to teach beginners.

Any suggestions? I filed a bug report

Hie @shane,

The shorter syntax such as:

dcc.Checklist(['New York City', 'Montreal', 'San Francisco'], ['Montreal'])

is available starting in dash V2.1.0, so upgrading the latest version should fix that error.

I noticed something odd though. When debug mode is off, this works.

dcc.Checklist(['New York City', 'Montreal', 'San Francisco'], 'Montreal')

But when debug mode is on, you need to put ["Montreal"] in a list. (I think that might be a bug)

Thank you @AnnMarieW and @shane for reporting this bug. The short syntax has been fixed, and like Ann said, it is available with Dash v2.1 or higher. Regarding the debug off mode allowing value as string instead of list, that should not be the case, so it’s definitely a bug. I reported this to our technical writers so we can fix it.

It works! Thanks for answering so quickly @AnnMarieW!

1 Like