gt
gt copied to clipboard
Format any cell based on value
Just found gt
and really like it. Using all the select
helpers is š
The only thing I haven't found is a simple solution to format cells of any column based on the cell value. In my app, the number of columns will vary based on the user's selection. In this reprex, I want to bold any value <= 5.
Some of the solutions I've found weren't easy to implement:
This solution uses rlang
+ purrr
https://community.rstudio.com/t/highlighting-values-in-gt/80608/2
This one uses a for loop across each column: https://stackoverflow.com/a/63945239/4650934
I was hoping to use something like:
tab_style(
style = ...,
locations = cells_body(
columns = ...,
condition = ~(.x <= 5))
)
)
I hope you'll consider adding a helper function to make this easy to do. Thanks for all the hard work.
library(tidyverse)
library(gt)
set.seed(123)
matrix(sample(1:30, 30), 3, 10) %>%
as_tibble() %>%
gt()

This seems like something that ought to be possible (and I would like this feature a lot). Thank you for suggesting it. Iām hoping that our ongoing work in improving the tidyselect support/semantics in this package will pave the way for your suggested code to work.