我使用 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和 documentation对于 DashTable,将 Python 语法转换为 Julia。我还尝试解决我的尝试产生的错误(例如“LoadError:语法:意外的','”),但没有成功。将不胜感激任何帮助!
编辑:我也一直在咨询conditional formatting documentation ,但语法是 Python,我在将其转换为 Julia 时仍然遇到问题。
最佳答案
我们不能将 filter_query
与 style_cell_conditional
一起使用。
我们可以将 filter_query
与 style_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
而不是 =
。
关于datatable - Dash 数据表中的条件格式值 (Julia),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66859952/