This is what I've got, but I get Error: object 'Name' not found
when I run the code. Any ideas on how to proceed?
library(gt)
data <- data.frame(
Name = c("John Doe", "Jane Smith", "Bob Johnson"),
Age = c(30, 25, 35))
highlight_word <- "Doe"
gt(data) |>
tab_style(
locations = cells_body(columns = Name),
style = list(cell_text(color =
ifelse(str_detect(Name, highlight_word), "yellow", "white"))))
A couple of approaches to try. One uses
fmt_markdown
to use Markdown-formatted text in your gt table with rendering. The other usestext_transform
to modify formatted strings in targeted cells in the table. The latter requires a function to transform the text as desired.With
fmt_markdown
:With
text_transform
:Output