图表未随下拉选择 Dash Plotly 更新 python
Graph not updating with dropdown selection Dash Plotly python
我正在尝试使用 dash plotly 构建条形图,当下拉列表正在 selected 时,无法使用下拉列表中的 selected 值刷新页面。我是 Dash 的新手。任何帮助都将是 appreciated.The 图是可以的,默认值是 selected(在这种情况下是“FII”),但是当我 select 不同的值(我有 FII, DII,Pro,Total) Client_Type.
中的值
df = df1[df1['Month'].isin([2,3])]
app = dash.Dash()
df = df1[df1['Month'].isin([2,3])]
app = dash.Dash()
party_data = []
for client in df['Client_Type'].unique():
party_data.append({'label': client, 'value': 'Client_Type'})
app.layout = html.Div([
dcc.Graph(id='graph'),
dcc.Dropdown(id='client-picker',options=party_data,value= 'FII' )
])
@app.callback(Output('graph', 'figure'),
[Input('client-picker', 'value')])
def update_figure(abc):
df1 = df[df.Client_Type == abc]
print(df1.head())
date1 = df1['Date']
Fut_Index_Long1 = df1['Fut_Index_Long']
return {
'data': [go.Bar(x=date1, y=Fut_Index_Long1)]
}
if __name__ == '__main__':
app.run_server(debug=True)
我认为您的下拉菜单选项配置有误。
字典中的标签是下拉列表中显示的值的名称。首先我会尝试:
for client in df['Client_Type'].unique():
party_data.append({'label': client, 'value': client})
以后可以格式化的标签。
我正在尝试使用 dash plotly 构建条形图,当下拉列表正在 selected 时,无法使用下拉列表中的 selected 值刷新页面。我是 Dash 的新手。任何帮助都将是 appreciated.The 图是可以的,默认值是 selected(在这种情况下是“FII”),但是当我 select 不同的值(我有 FII, DII,Pro,Total) Client_Type.
中的值 df = df1[df1['Month'].isin([2,3])]
app = dash.Dash()
df = df1[df1['Month'].isin([2,3])]
app = dash.Dash()
party_data = []
for client in df['Client_Type'].unique():
party_data.append({'label': client, 'value': 'Client_Type'})
app.layout = html.Div([
dcc.Graph(id='graph'),
dcc.Dropdown(id='client-picker',options=party_data,value= 'FII' )
])
@app.callback(Output('graph', 'figure'),
[Input('client-picker', 'value')])
def update_figure(abc):
df1 = df[df.Client_Type == abc]
print(df1.head())
date1 = df1['Date']
Fut_Index_Long1 = df1['Fut_Index_Long']
return {
'data': [go.Bar(x=date1, y=Fut_Index_Long1)]
}
if __name__ == '__main__':
app.run_server(debug=True)
我认为您的下拉菜单选项配置有误。 字典中的标签是下拉列表中显示的值的名称。首先我会尝试:
for client in df['Client_Type'].unique():
party_data.append({'label': client, 'value': client})
以后可以格式化的标签。