First time user of Dash (very impressed by the way) so I’m hoping this is just an oversight on my part. I created a graph with two drop down menus that interact with each other. This works great. I want users to be able to select multiple items from the second drop down. I added multi=True
but when I go to click the items I get the error ValueError: Arrays were different lengths
.
This is what I’ve tried:
app.layout = html.Div([
html.H3(
children='Aggregated Number of Graduates in Education by State',
style={
'textAlign': 'center',
}
),
html.Div([
html.Div([
dcc.Dropdown(
id='state-id',
options=[{'label': i, 'value': i} for i in state],
value = 'Alaska'
)
],
style={'width': '48%', 'display': 'inline-block'}),
html.Div([
dcc.Dropdown(
id='indicator-id',
options=[{'label': i , 'value': i} for i in available_indicators],
value='state total',
multi=True
)
],
style={'width':'48%', 'float': 'right', 'display': 'inline-block'})
]),
dcc.Graph(id='indicator-graphic')
])
@app.callback(
dash.dependencies.Output('indicator-graphic', 'figure'),
[dash.dependencies.Input('state-id', 'value'),
dash.dependencies.Input('indicator-id', 'value')])
def update_time_series(state_id, indicator_id):
dff = df[df['state_long'] == state_id]
return {
'data' : [go.Scatter(
x = dff[dff['indicator'] == indicator_id]['year'],
y = dff[dff['indicator'] == indicator_id]['value'],
mode='lines')],
'layout' : go.Layout(
xaxis={'title': 'Year'},
yaxis={'title': 'Total Graduates in Education'}
)
}
Is this an error in how I structured the data or is there something else going on?
Thanks for you help.