Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format any cell based on value #703

Closed
rjake opened this issue Dec 22, 2020 · 1 comment · Fixed by #1066
Closed

Format any cell based on value #703

rjake opened this issue Dec 22, 2020 · 1 comment · Fixed by #1066

Comments

@rjake
Copy link

rjake commented Dec 22, 2020

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()

@rich-iannone
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment