【问题标题】:Graph not updating with dropdown selection Dash Plotly python图表未通过下拉选择 Dash Plotly python 更新
【发布时间】:2020-03-30 05:58:52
【问题描述】:

我正在尝试使用 dash plotly 构建条形图,当下拉列表被选中时,它无法使用下拉列表中的选定值刷新页面。我是 Dash 的新手。任何帮助将不胜感激。图表可以选择默认值(在这种情况下为“FII”),但是当我在 Client_Type 中选择不同的值(我有 FII、DII、Pro、Total)值时。

    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)

【问题讨论】:

    标签: python graph plotly plotly-dash


    【解决方案1】:

    我认为您的 Dropdown 选项配置错误。 dict 中的 label 是 Dropdown 中显示的值的名称。首先我会尝试:

       for client in df['Client_Type'].unique():
                 party_data.append({'label': client, 'value': client})
    

    以后可以格式化的标签。

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 2022-01-08
      • 2019-01-23
      • 1970-01-01
      • 2020-03-19
      • 2021-10-28
      • 1970-01-01
      • 2020-09-12
      • 2019-01-06
      相关资源
      最近更新 更多