datatable - Dash 数据表中的条件格式值 (Julia)

标签 datatable formatting julia plotly-dash

我使用 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

得出此表:

enter image description here

我正在尝试对包含“Egg”的单元格进行条件格式设置,但遇到了麻烦。我尝试过关注 other examplesdocumentation对于 DashTable,将 Python 语法转换为 Julia。我还尝试解决我的尝试产生的错误(例如“LoadError:语法:意外的','”),但没有成功。将不胜感激任何帮助!

编辑:我也一直在咨询conditional formatting documentation ,但语法是 Python,我在将其转换为 Julia 时仍然遇到问题。

最佳答案

我们不能将 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)
]

结果:

enter image description here


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

关于datatable - Dash 数据表中的条件格式值 (Julia),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66859952/

相关文章:

.net - 格式化 LINQ 查询的最佳方法

Julia 微分方程.jl : EnsembleProblem where tspan is varied

html - 在数据表中居中响应展开图标

c# - 如何对给定列和方向的 DataTable 进行排序?

ruby - 如何格式化 BigDecimal 以仅显示所需数量的十进制数字?

Julia :你能为评估设定一个时间限制吗

julia - 如何计算 Julia 泊松分布的概率

datatable - Google DataTable 的 getRow() 方法是否已弃用?

javascript - 在 Javascript 中使用 YUI,如何在数据表/滚动数据表上绘制叠加层?

python - 替换 % 后跟字符串中的数字