小编j_9*_*_90的帖子

使用下拉列表在 Plotly 中交互式过滤数据表

我正在尝试制作一个交互式表格,其中通过从下拉列表中选择一个值来更改表格的值。这应该只在 Plotly(而不是 Dash)中完成,因为我需要与其他用户共享文件。

例如:

如果我选择 Channel_1 那么表格应该是

日期 A_项目 B_项目 C_项目
2020-01-27 2 1 9
2020-02-27 8 7 2

如果我选择 Channel_2 那么表格应该是

日期 A_项目 B_项目 C_项目
2020-03-27 0 10 9
import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({"Date":["2020-01-27","2020-02-27","2020-03-27"],
                   "A_item":[2, 8, 0],
                   "B_item":[1, 7, 10],
                   "C_item":[9, 2, 9],
                   "Channel_type":["Channel_1", "Channel_1", "Channel_2"]
                   })

fig = go.Figure()
fig.add_trace(go.Table(
    header=dict(
        values=items,
        font=dict(size=10),
        align="left"
    ),
    cells=dict(
        values=..... ,
        align = "left")
    ))

updatemenu= []
buttons=[]
for channel in df['Channel_type'].unique():
    buttons.append(dict(method='update',
                        label=channel,
                        args=[{.....}]) …
Run Code Online (Sandbox Code Playgroud)

python dataframe plotly dropdown plotly-python

4
推荐指数
1
解决办法
8348
查看次数

标签 统计

dataframe ×1

dropdown ×1

plotly ×1

plotly-python ×1

python ×1