Use tidyselect in gt::data_color()

I am trying to use tidyselect() functions within the data_color() function of gt.

This works:

library(tidyverse)
library(gt)

iris %>% group_by(Species) %>% 
  summarize(across(everything(), mean)) %>% 
  gt() %>% 
  data_color(columns = vars(Sepal.Length, Sepal.Width),
             colors = scales::col_numeric(palette = paletteer::paletteer_d(palette = "ggsci::red_material") %>% as.character(),
                                          domain = NULL))


And I had expected this would be identical:

iris %>% group_by(Species) %>% 
  summarize(across(everything(), mean)) %>% 
  gt() %>% 
  data_color(columns = vars(starts_with('Sepal')),
             colors = scales::col_numeric(palette = paletteer::paletteer_d(palette = "ggsci::red_material") %>% as.character(),
                                          domain = NULL))

but instead I get the error "Error: Can't convert a call to a string".

What am I missing?

I think you can just drop the 'vars()'

iris %>% group_by(Species) %>% 
  summarize(across(everything(), mean)) %>% 
  gt() %>% 
  data_color(columns =starts_with("Sepal"),
             colors = scales::col_numeric(palette = paletteer::paletteer_d(palette = "ggsci::red_material") %>% as.character(),
                                          domain = NULL))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Right you are. Thanks!