Skip to content

How to set background colors for the cells of multiple columns based on string contents #863

@ahbon123

Description

@ahbon123

Hello, say I have a small dataset as follows:

library(gt)
library(tidyverse)

id <- c(1,2,3,4,5)
res1 <- c("true", "true", "false", "true", "false")
res2 <- c("false", NA, NA, "true", "true")
df <- data.frame(id, res1, res2)

df %>% 
  gt()

For columns res1 and res2, let's say if value content are trues, I'll need to highlight that cell with red background color, if falses, highlight with green color, for other cases, keep their colors as original.

Is it possible to achieve that using gt package?

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions