【发布时间】:2019-08-21 12:27:10
【问题描述】:
我无法弄清楚为什么我的图表没有使用我选择的值中的数据进行更新。有人可以帮忙吗?
我已经尝试重写了很多次,但我似乎无法理解在应用回调之后我必须编写的函数以及我应该在这个函数中返回什么。
app = dash.Dash()
app.layout = html.Div(children = [
html.H1('Sports PA Dashboard'),
dcc.Dropdown(
id='sport_dropdown',
options=[{'label': i, 'value': i} for i in df.Sport.unique()],
value = df.Sport.unique()),
dcc.Graph(id='age_vs_rank')
])
@app.callback(
dash.dependencies.Output('age_vs_rank', 'figure'),
[dash.dependencies.Input('sport_dropdown', 'value')])
def update_output(selected_sport):
print(selected_sport)
sport = df[df.Sport == selected_sport]
rank = sport['Rank']
age = sport['Age']
dcc.Graph(id='age_vs_rank',
figure={
'data' : [{'x':rank, 'y':age, 'type' : 'bar', 'name' : 'age_vs_rank'}],
'layout' : {
'title' : 'Age vs Rank'
}
})
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
标签: python plotly-dash