使用下拉过滤器更新Dash图

时间:2019-07-12 07:43:16

标签: python plotly-dash

我正在寻找2个下拉菜单(一个用于日期,另一个用于sect_id)来过滤和更新仪表板上的绘图,我对创建的回调和函数感到非常困惑。这是我的数据:

query.launched = query.launched + 1
query.modified = until
db.session.commit()

我希望将Measure1与Measure3进行分散,并具有两个下拉菜单。这是我所做的:

  sect_id   Date    Measure1  Measure2  Measure3  Total %
  L19801  01-01-17    12        65        0       33
  L19801  01-01-17    19        81        7       45
  M18803  01-01-17    15        85        7       45
  M19803  01-01-17    20        83        2       52
  xxxxxx  xxxxxxx     xx        xx        x       xx
  xxxxxx  xxxxxxx     xx        xx        x       xx

我目前仅尝试使用一个下拉菜单(日期),并且对所做的布局,下拉菜单和回调函数感到非常困惑。

1 个答案:

答案 0 :(得分:0)

布局是仪表板,图形和下拉菜单的内容。回调是所述组件之间的交互。请参考Dash文档: For basic info about layoutfor callbacks

您可以相当简单地创建回调,只需定义一个函数并向其添加回调装饰器即可,

import plotly.graph_objs as go
from dash.dependencies import Input, Output

@app.callback( 
    # What does the callback change? Right now we want to change the figure of the graph.
    # You can assign only one callback for each property of each component.
Output(component_id='graph', component_property='figure'), 

    # Any components that modify the outcome of the callback
    # (sect_id picker should go here as well)
    [Input(component_id='date_picker', component_property='value')]) 
def create_graph_figure(date_picker_value):
    # you should define a function here that returns your plot
    df_filtered = df[df['Date'] == date_picker_value]
    return go.Scatter(x=df['Measure1'], y=df['Measure2'])