Dash 数据中的条件格式化值 table (Julia)
Conditionally formatting values in Dash data table (Julia)
我使用 Julia 在 Dash 中构建了一个 table:
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
导致这个 table:
我正在尝试有条件地格式化包含“Egg”的单元格,但我遇到了问题。我试过为 DashTable 遵循 other examples and the documentation,将 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
而不是 =
.
我使用 Julia 在 Dash 中构建了一个 table:
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
导致这个 table:
我正在尝试有条件地格式化包含“Egg”的单元格,但我遇到了问题。我试过为 DashTable 遵循 other examples and the documentation,将 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
而不是 =
.