【问题标题】:Conditionally formatting values in Dash data table (Julia)Dash 数据表 (Julia) 中的条件格式值
【发布时间】:2021-03-29 18:53:40
【问题描述】:

我已经使用 Julia 在 Dash 中构建了一个表格:

df = DataFrame(Day=["Monday","Tuesday","Wednesday"],
               Object=["Egg","Cat","Phone"],
               Letters=["A","B","C"],
               Food=["Milk","Egg","Cheese"])

app = dash()

app.layout = html_div() do
    dash_datatable(id="data_table",
                   columns = tuple([(name=x,id=x) for x in names(df)])[1],
                   data = df_to_datatable(df),
                   style_cell = (textAlign="center", fontSize=16,
                                 backgroundColor="rgb(50,50,50)",
                                 color="white"),
                   style_header = (backgroundColor="rgb(30, 30, 30)",),
                   style_table = (textAlign="center", minwidth="35%",
                                  width="35%",maxwidth="35%",
                                  marginLeft="auto",marginRight="auto"),
                   #style_cell_conditional = (if(filter_query="Egg"), backgroundColor="#3D9970"),
                  ),
    html_div(id="output_div")
end

生成此表:

我正在尝试有条件地格式化包含“Egg”的单元格,但我遇到了问题。我尝试关注other examples 和 DashTable 的documentation,将 Python 语法转换为 Julia。我还尝试解决我的尝试产生的错误(例如“LoadError:语法:意外','”)但没有成功。非常感谢任何帮助!

编辑:我也一直在咨询conditional formatting documentation,但语法是 Python,我仍然无法转换为 Julia。

【问题讨论】:

  • 感谢您提供的链接,@as11 -- 我一直将此页面用作参考,但我仍然无法将 Python 语法转换为 Julia。这很有帮助,但不会立即回答我的问题。
  • @BasvanderLinden -- 实际上,代码会生成显示的表格。没有语法错误。

标签: datatable formatting julia plotly-dash


【解决方案1】:

我们不能将filter_querystyle_cell_conditional 一起使用。

我们可以像这样使用filter_querystyle_data_conditional

style_data_conditional = [
    Dict(
        "if" =>
            Dict("column_id" => "$(column)", "filter_query" => "{$(column)} = 'Egg'"),
        "backgroundColor" => "blue",
    ) for column in names(df)
]

结果:


以上内容与'Egg' 完全匹配。如果要匹配所有包含"Egg" 的单词,可以使用contains 而不是=

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    相关资源
    最近更新 更多