Conditional formatStyle in DT

有些话、适合烂在心里 提交于 2019-12-04 16:48:52

Try something like this:

library(DT)
datatable(test) %>%
    formatStyle(
        columns = c("mobile_number", "home_number"),
        valueColumns = c("mobile_flag", "home_number_flag"),
        backgroundColor = styleEqual(c("correct", "incorrect"), 
                                     c("green", "red"))
    )

columns specifies which columns you would like to conditionally format. valueColumns specifies which columns should be evaluated using the conditions specified in styleEqual of backgroundColor.

Note that order in columns corresponds with order in valueColumns (e.g "mobile_number" is conditionally colored by "mobile_flag").

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!