Hi All! I’m trying to add a ´go.Scatter´ to my dashboard. This line chart comes from this df:
year region CAT1 CAT2 CAT3
2018 Europe 7.81 7.95 12
2017 Europe 7.78 7.93 13
2016 Europe 7.63 7.78 14
2018 Middle East 5.2 5.2 151
2017 Middle East 5.03 5.03 151
2016 Middle East 5.3 5.3 152
2018 Africa 5.48 5.4 144
2017 Africa 5.39 5.26 148
2016 Africa 5.85 5.76 138
I’ve created a dropdown menu for CAT1
, CAT2
, CAT3
, so when you select the category, you should see a line chart showing the values for each region
over time (year). This is what my code looks like, but it’s not running:
app.layout = html.Div([
html.Div([
dcc.Dropdown(
id='category',
options=[{'label': i.title(), 'value': i} for i in categories],
value='CAT1'
)
]),
dcc.Graph(id='feature-graphic')
], style={'padding':10})
@app.callback(
Output('feature-graphic', 'figure'),
[Input('category', 'value')])
def update_graph(category):
return {
'data': [go.Scatter(
x=df.groupby('year'),
y=df.groupby('region')[i],
color = df['region'],
mode='lines'
) for i in categories],
'layout': go.Layout(
xaxis={'title': 'Year'},
yaxis={'title': 'Score'},
margin={'l': 40, 'b': 40, 't': 10, 'r': 0},
hovermode='closest'
)
}
Does this make sense?
Thanks for your help!