简体   繁体   English

python中带有plotly的多个过滤器数据下拉表

[英]Multiple filter data dropdown table with plotly in python

I am currently trying to generate a table with multiple dropdown options (in a Jupiter Notebook).我目前正在尝试生成一个具有多个下拉选项的表(在 Jupiter Notebook 中)。 I have been able to create the scenario but the dropdown buttons work independently, meaning that if I select one dropdown from my 'Decision' dropdown with option 'A' and then select the other downtown 'Sex' with option 'Female' I either get option A or option 2 depending on the button last selected.我已经能够创建场景,但下拉按钮独立工作,这意味着如果我使用选项“A”从“决策”下拉列表中选择一个下拉菜单,然后使用选项“女性”选择另一个市中心的“性别”,我要么得到选项 A 或选项 2 取决于最后选择的按钮。 However, what I really want is to have both filters applied at the same time.但是,我真正想要的是同时应用两个过滤器。 So I would get all Decisions 'A' that are 'Female' as filters for my table.因此,我会将所有“女性”的决策“A”作为我表的过滤器。

This is my code:这是我的代码:

fig = go.Figure(go.Table(header={"values": df_dash.columns,'fill_color':'navy','align':'left',
                                 'font':dict(color='white', size=12)}, 
                         cells={"values": df_dash.T.values,'fill_color':'white','align':'left'}))
fig.update_layout(
    updatemenus=[
        {
            "y": 1 - (i / 5),
            "buttons": [
                {
                    "label": c,
                    "method": "restyle",
                    "args": [
                        {
                            "cells": {
                                "values": df_dash.T.values
                                if c == "All"
                                else df_dash.loc[df_dash[menu].eq(c)].T.values
                            }
                        }
                    ],
                }
                for c in ["All"] + df_dash[menu].unique().tolist()
                
            ],
            
        }
        for i, menu in enumerate(["Decision", "Sex",])
    ]
)

And this is how it looks:这就是它的外观:

表视图

Any ideas what am I doing wrong or what can I add to make both buttons actively filtering my df table at the same time?任何想法我做错了什么或者我可以添加什么来使两个按钮同时主动过滤我的 df 表?

Based on this answer in the plotly forums, you cannot create buttons that are dependent on each other.根据情节论坛中的这个答案,您无法创建相互依赖的按钮。

The best you could probably do is create one dropdown with every possible combination in your current Decision and Sex dropdowns – which I understand probably isn't ideal.您可能做的最好的事情就是在您当前的DecisionSex下拉列表中创建一个包含所有可能组合的下拉列表——我知道这可能并不理想。

If you are willing to use plotly-dash , then it is possible as you can create two dropdowns that are inputs to a basic callback that updates the fig, as shown in this example in the plotly-dash documentation如果您愿意使用plotly-dash ,那么您可以创建两个下拉菜单,作为更新无花果的基本回调的输入,如 plotly-dash 文档中的此示例所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM