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': 'https://codepen.io/chriddyp/pen/bWLwgP.css'})
app.layout = html.Div(
children = [
html.Div(
id = 'list',
children = [ dcc.Checklist(id = "myList")]),
html.Button('Fill Checklist', id='list-btn', n_clicks=0)]
)
@app.callback(
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__':
app.run_server(debug=True)
#dcc.RadioItems
and i got:
the console shows:
127.0.0.1 - - [21/Dec/2017 04:04:07] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [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\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Raul\Anaconda3\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Raul\Anaconda3\lib\site-packages\dash\dash.py", line 165, in serve_layout
cls=plotly.utils.PlotlyJSONEncoder),
File "C:\Users\Raul\Anaconda3\lib\json\__init__.py", line 237, in dumps
**kw).encode(obj)
File "C:\Users\Raul\Anaconda3\lib\site-packages\plotly\utils.py", line 136, in encode
encoded_o = super(PlotlyJSONEncoder, self).encode(o)
File "C:\Users\Raul\Anaconda3\lib\json\encoder.py", line 198, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\Raul\Anaconda3\lib\json\encoder.py", line 256, in iterencode
return _iterencode(o, 0)
File "C:\Users\Raul\Anaconda3\lib\site-packages\plotly\utils.py", line 204, in default
return _json.JSONEncoder.default(self, obj)
File "C:\Users\Raul\Anaconda3\lib\json\encoder.py", 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
127.0.0.1 - - [21/Dec/2017 04:04:11] "GET /_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [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.
Thank’s