我正在尝试为值进行一些条件着色。问题是我已经在 StackOverflow 和 reactable wiki 上阅读了一些帖子,但它们都没有工作!
reactable(prueba,
defaultColDef = colDef(
header = function(value) gsub(".", " ", value, fixed = TRUE),
cell = function(value) format(value, nsmall = 1),
align = "center",
minWidth = 150,
headerStyle = list(background = "#f7f7f8")
),
bordered = TRUE,
highlight = TRUE,
defaultSortOrder = "desc",
filterable = TRUE, minRows = 20,
groupBy = "linea",
columns = list(
Inventory = colDef(aggregate = "sum"),
OCC = colDef(aggregate = "mean"),
Tickets.Vendidos = colDef(aggregate = "sum"),
Revenue = colDef(aggregate = "sum"),
RASK = colDef(aggregate = "mean"),
CASK = colDef(aggregate = "mean"),
Rating = colDef(aggregate = 'mean'),
CpS = colDef(aggregate = 'mean'),
Red.discount = colDef(aggregate = 'sum'),
PC1 = colDef(aggregate = 'mean'),
PC1_margin = colDef(aggregate = 'mean'),
ASP = colDef(aggregate = 'mean')
)
)
这是我的代码!!!我希望在 OCC 列中添加条件。
我希望它是:
红色如果
0 <= OCC < 0.25
橙色如果
0.25 <= OCC < 0.5
黄色如果
0.5 <= OCC < 0.75
绿色如果
0.75 <= OCC <= 1
我尝试在我的OCC
专栏中使用它:
style = function(value) {
if (value > 0) {
color <- "#008000"
} else if (value < 0) {
color <- "#e00000"
} else {
color <- "#777"
}
list(color = color, fontWeight = "bold")
}
但没有工作:(
请帮我!!!!