R 需要跨数据表的一行应用条件格式
我试图使用styleInterval(在DT包的formatStyle中)将条件格式应用于数据表的一行。我在网上找到的所有示例都是用于格式化整个datatable、限制所涉及的列,或者基于单个列中的值格式化整行 在下面的示例中,我想将涉及的行限制为仅第一行(“entity1”)R 需要跨数据表的一行应用条件格式,r,dt,R,Dt,我试图使用styleInterval(在DT包的formatStyle中)将条件格式应用于数据表的一行。我在网上找到的所有示例都是用于格式化整个datatable、限制所涉及的列,或者基于单个列中的值格式化整行 在下面的示例中,我想将涉及的行限制为仅第一行(“entity1”) entity <- c('entity1', 'entity2', 'entity3') value1 <- c(21000, 23400, 26800) value2 <- c(21234, 2344
entity <- c('entity1', 'entity2', 'entity3')
value1 <- c(21000, 23400, 26800)
value2 <- c(21234, 23445, 26834)
value3 <- c(21123, 234789, 26811)
value4 <- c(27000, 23400, 26811)
entity.data <- data.frame(entity, value1, value2, value3, value4)
DT::datatable(entity.data) %>%
formatStyle(columns = 2:5,
backgroundColor = styleInterval(cuts = c(21200,22000),
values = c('red','white','green')))
实体使用行回调
:
library(DT)
entity <- c('entity1', 'entity2', 'entity3')
value1 <- c(21000, 23400, 26800)
value2 <- c(21234, 23445, 26834)
value3 <- c(21123, 234789, 26811)
value4 <- c(27000, 23400, 26811)
entity.data <- data.frame(entity, value1, value2, value3, value4)
rowCallback <- c(
"function(row, dat, displayNum, index){",
" if(index == 0){",
" for(var j=2; j<dat.length; j++){",
" var x = dat[j];",
" var color = x <= 21200 ? 'red' : x <= 22000 ? 'white' : 'green';",
" $('td:eq('+j+')', row)",
" .css('background-color', color);",
" }",
" }",
"}"
)
datatable(entity.data,
options =
list(rowCallback = JS(rowCallback))
)
库(DT)
实体使用行回调
:
library(DT)
entity <- c('entity1', 'entity2', 'entity3')
value1 <- c(21000, 23400, 26800)
value2 <- c(21234, 23445, 26834)
value3 <- c(21123, 234789, 26811)
value4 <- c(27000, 23400, 26811)
entity.data <- data.frame(entity, value1, value2, value3, value4)
rowCallback <- c(
"function(row, dat, displayNum, index){",
" if(index == 0){",
" for(var j=2; j<dat.length; j++){",
" var x = dat[j];",
" var color = x <= 21200 ? 'red' : x <= 22000 ? 'white' : 'green';",
" $('td:eq('+j+')', row)",
" .css('background-color', color);",
" }",
" }",
"}"
)
datatable(entity.data,
options =
list(rowCallback = JS(rowCallback))
)
库(DT)
实体