对于我的可反应表,我想创建一个比较两列的函数,即今年一列和去年一列。我希望函数根据它是否高于或低于去年的值来为当前年份列中的值着色。因此,如果值更高,它应该变成绿色,等等。
我的函数大部分工作,但我无法让函数访问函数中值的索引号。
这是我到目前为止所拥有的:
library(reactable)
reactable(test,
highlight = TRUE,
defaultPageSize = 20,
columns = list(
Maand = colDef(footer = "Totaal"),
year2020 = colDef(style = function(value) {
if (value > test[....index of value here...., "year2019"] ) {
color <- "#008000"
} else if (value >1) {
color <- "#e00000"
} else {
color <- "#777"
}
list(color = color, fontWeight = "bold")
})
),
defaultColDef = colDef(footer = function(values) {
if (!is.numeric(values)) return()
sum(values)
},
footerStyle = list(fontWeight = "bold")),
rowClass = "my-row"
)
当我使用这样的随机索引号时,它确实有效:
reactable(test,
highlight = TRUE,
defaultPageSize = 20,
columns = list(
Maand = colDef(footer = "Totaal"),
year2020 = colDef(style = function(value) {
if (value > test[1, "year2019"] ) {
color <- "#008000"
} else if (value >1) {
color <- "#e00000"
} else {
color <- "#777"
}
list(color = color, fontWeight = "bold")
})
),
defaultColDef = colDef(footer = function(values) {
if (!is.numeric(values)) return()
sum(values)
},
footerStyle = list(fontWeight = "bold")),
rowClass = "my-row"
)
谁能告诉我我做错了什么?提前致谢!