Filling a checklist through a callback

Hello everyone!

First of all, thank you for this wonderful library.

I have a problem to fill a Checklist through a callback. My code is the next:

import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.css.append_css({'external_url': ''})


app.layout = html.Div(
			children = [
				id = 'list',
				children = [ dcc.Checklist(id = "myList")]),
			html.Button('Fill Checklist', id='list-btn', n_clicks=0)]

	Output('myList', 'options'),
	[Input('list-btn', 'n_clicks')]
def fillChecklist(n_clicks):
    data = [['label-1', '1'],['label-2', '2']]
    return [{'label': x[0] +" "+ x[1], 'value' : x[1] } for x in data]

if __name__ == '__main__':


and i got:


the console shows: - - [21/Dec/2017 04:04:07] "GET / HTTP/1.1" 200 - - - [21/Dec/2017 04:04:11] "GET /_dash-layout HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 33, in reraise
    raise value
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 33, in reraise
    raise value
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\dash\", line 165, in serve_layout
  File "C:\Users\Raul\Anaconda3\lib\json\", line 237, in dumps
  File "C:\Users\Raul\Anaconda3\lib\site-packages\plotly\", line 136, in encode
    encoded_o = super(PlotlyJSONEncoder, self).encode(o)
  File "C:\Users\Raul\Anaconda3\lib\json\", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\Raul\Anaconda3\lib\json\", line 256, in iterencode
    return _iterencode(o, 0)
  File "C:\Users\Raul\Anaconda3\lib\site-packages\plotly\", line 204, in default
    return _json.JSONEncoder.default(self, obj)
  File "C:\Users\Raul\Anaconda3\lib\json\", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
  File "<string>", line 52, in __repr__
  File "<string>", line 52, in <listcomp>
  File "<string>", line 52, in __repr__

RecursionError: maximum recursion depth exceeded while calling a Python object - - [21/Dec/2017 04:04:11] "GET /_dash-dependencies HTTP/1.1" 200 - - - [21/Dec/2017 04:04:11] "GET /favicon.ico HTTP/1.1" 200 -

When I change the dcc.Checklist() for dcc.RadioItems() the code worrks fine:


I don’t know what I’m doing wrong or if it’s a kind o bug. I would greatly appreciate your help or I want to know if someone has another way to fill a checklist.

The problem is that the checklist component must have an initial value provided for its values attribute. Even though you’re generating the value of that attribute with the callback, the component must have a specified value on initialisation. values=[] seems to make it happy.

Edit: I’ve just filed an issue over on the dash-core-components repository about this –

1 Like

I commented about this in the issue above ( Thanks for reporting and triaging!