Closed JFern83 closed 1 year ago
final_table <- df %>%
group_by(Unit, Course) %>%
summarise_at(.vars = c("RR", "Score"), .funs = ~mean(., na.rm = T)) %>%
arrange(desc(Score)) %>%
gt() %>%
cols_label(
RR = ("Response Rate %"),
Score = "Mean Score") %>%
opt_align_table_header(align = "left") %>%
fmt_number(columns = Score) %>%
fmt_number(columns = RR, scale_by = 100/1, decimals = F) %>%
cols_width(
Unit ~ px(150),
RR ~px(150),
Score ~px(150)) %>%
cols_align("center") %>%
data_color(
columns = Score,
colors = scales::col_numeric(
palette = c(
"red","orange","green"),
domain = c(3,3.5,4.0,4.5,5)))
#> Error in df %>% group_by(Unit, Course) %>% summarise_at(.vars = c("RR", : could not find function "%>%"
Created on 2023-07-08 with reprex v2.0.2
Do you see this only with pagedown output ? Or is it the same output in R console when you run the gt code ?
Why open the issue in this repo ? Your example does not even use pagedown.
You have some Q&A forum dedicated to generic question (like https://community.rstudio.com/). Wouldn't it be better to ask there for gt community to help ?
Yes apologies, new to Github and think I've posted this issue in the wrong place! The general Q&A forum looks much more appropriate.
If interested, it is in the R console that the problem occurred, but by adding ungroup
prior to passing to gt()
the problem was resolved.
I am using GT table and am confused by how it is generating the output.
Code is below. Before passing it through gt() the dataframe produced by the "group_by" function formats the table as expected i.e. 4 headings and 12 rows. After gt() it does something odd to to the 'course' and 'unit' variables, pics below. Any ideas or suggestions for formatting the gt table in the same way the dataframe is constructed?
final_table <- df %>% group_by(Unit, Course) %>% summarise_at(.vars = c("RR", "Score"), .funs = ~mean(., na.rm = T)) %>% arrange(desc(Score)) %>% gt() %>% cols_label( RR = ("Response Rate %"), Score = "Mean Score") %>% opt_align_table_header(align = "left") %>% fmt_number(columns = Score) %>% fmt_number(columns = RR, scale_by = 100/1, decimals = F) %>% cols_width( Unit ~ px(150), RR ~px(150), Score ~px(150)) %>% cols_align("center") %>% data_color( columns = Score, colors = scales::col_numeric( palette = c( "red","orange","green"), domain = c(3,3.5,4.0,4.5,5)))