下面是一个解决方案:
rowCallback <- c(
"function(row, data, displayNum, displayIndex, dataIndex){",
" if(data[1] === 4.7){",
" $(row).find('td').addClass('red');",
" }",
"}"
)
shinyApp(
ui = fluidPage(
tags$head(
tags$style(
HTML(
"table.dataTable tbody tr td.red {background-color: #fc8a8a !important}"
)
)
),
DTOutput("table")
),
server = function(input, output, session) {
output$table <- renderDT({
head(iris) %>%
datatable(options = list(rowCallback = JS(rowCallback))) %>%
formatStyle(c(2,4), backgroundColor = "#fcf4d9")
})
}
)