Discovery: dash_core_components Dropdown() requires explicitly labeled options
MarkPundurs
Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Registered Posts: 27 ✭✭✭✭
I was unable to get a dash_core_components Dropdown control to display non-null options in a webapp using the parameter format
options=['New York City', 'Montreal', 'San Francisco']
It worked only when I changed this to
options=[{'label': i, 'value': i} for i in ['New York City', 'Montreal', 'San Francisco']]
Operating system used: Linux
Best Answer
-
Hi @MarkPundurs
,The following code works for me using Dash v2.7.0:
from dash import dcc, html, Dash, Input, Output options = ['New York City', 'Montreal', 'San Francisco'] app.layout = html.Div(children=[ dcc.Dropdown(options, id='demo-dropdown'), html.Div(id='dd-output-container') ]) @app.callback( Output('dd-output-container', 'children'), Input('demo-dropdown', 'value') ) def update_output(value): return f'You have selected {value}'
Could you please share a full code example, a screenshot of the issue, and the Dash version that you're using?
Thanks,
Zach
Answers
-
I was on dash 1.21; once I upgraded, your code worked, as does
dcc.Dropdown(options, id='demo-dropdown', value='Montreal', multi=True)