Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 需要跨数据表的一行应用条件格式_R_Dt - Fatal编程技术网

R 需要跨数据表的一行应用条件格式

R 需要跨数据表的一行应用条件格式,r,dt,R,Dt,我试图使用styleInterval(在DT包的formatStyle中)将条件格式应用于数据表的一行。我在网上找到的所有示例都是用于格式化整个datatable、限制所涉及的列,或者基于单个列中的值格式化整行 在下面的示例中,我想将涉及的行限制为仅第一行(“entity1”) entity <- c('entity1', 'entity2', 'entity3') value1 <- c(21000, 23400, 26800) value2 <- c(21234, 2344

我试图使用styleInterval(在DT包的formatStyle中)将条件格式应用于数据表的一行。我在网上找到的所有示例都是用于格式化整个datatable、限制所涉及的列,或者基于单个列中的值格式化整行

在下面的示例中,我想将涉及的行限制为仅第一行(“entity1”)

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)
实体