使用下拉过滤器更新虚线图

2024-06-16 10:13:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望有2个下拉菜单(一个是日期,另一个是sect_id)来过滤和更新我的仪表板上的绘图,我觉得很困惑的回调和函数创建。以下是我的数据:

  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对测量3和有两个下拉菜单。我所做的:

^{pr2}$

我目前只尝试了一个下拉(日期),我很困惑我做了什么布局,下拉和回调。在


Tags: 数据id绘图date仪表板xx下拉菜单xxxxxx
1条回答
网友
1楼 · 发布于 2024-06-16 10:13:13

布局是仪表板、图形和下拉列表的内容。回调是所述组件之间的交互。请参考仪表板文档: 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'])

相关问题 更多 >