Shiny 使用JavaScript在DataTable中使用颜色格式化行

Shiny 使用JavaScript在DataTable中使用颜色格式化行,shiny,colors,dt,Shiny,Colors,Dt,如何修改此线程中的代码以将颜色格式应用于整行,而不仅仅是特定单元格 特别是这个, changeCellColor <- function(row, col){ c( "function(row, data, num, index){", sprintf(" if(index == %d){", row-1), sprintf(" $('td:eq(' + %d + ')', row)", col

如何修改此线程中的代码以将颜色格式应用于整行,而不仅仅是特定单元格

特别是这个,

changeCellColor <- function(row, col){
  c(
    "function(row, data, num, index){",
    sprintf("  if(index == %d){", row-1),
    sprintf("    $('td:eq(' + %d + ')', row)", col),
    "    .css({'background-color': 'orange'});",
    "  }",
    "}"  
  )
}
datatable(dat, 
          options = list(
            dom = "t",
            rowCallback = JS(changeCellColor(1, 2))
          )
)
changeCellColor给你:

changeCellColor <- function(row){
  c(
    "function(row, data, num, index){",
    sprintf("  if(index == %d){", row-1),
    "for(n = 0; n <= 4; n++) {",
    "  $('td:eq(' + n + ')', row)",
    "    .css({'background-color': 'orange'});",
    "}",
    "  }",
    "}"  
  )
}
datatable(dat, 
          options = list(
            dom = "t",
            rowCallback = JS(changeCellColor(1))
          )
)
changeCellColor