rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.01k stars 204 forks source link

opt_interactive seems to be removing grand total summary rows #1359

Open novotny1akub opened 1 year ago

novotny1akub commented 1 year ago

Thank you so much for gt! It's a great package and there's ton of awesome new stuff coming with 0.9 release. As for the issue, it seems like the opt_interactivefunction collides with the grand_summary_rowsfunction. Below is a reprex. Possibly related to https://github.com/rstudio/gt/issues/1307 and https://github.com/rstudio/gt/issues/1299.

library(gt)
library(tidyverse)

pizzaplace %>%
  head(5) %>%
  select(type, price) %>%
  gt() %>%
  grand_summary_rows(columns = price, fns = "sum") %>%
  opt_interactive() # seems like the opt_interactive removes the grand summary row
image
sessionInfo()
#> R version 4.1.1 (2021-08-10)
#> Platform: i386-w64-mingw32/i386 (32-bit)
#> Running under: Windows 10 x64 (build 22621)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250   
#> [3] LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C                  
#> [5] LC_TIME=Czech_Czechia.1250    
#> system code page: 1252
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.28     withr_2.4.2       R.methodsS3_1.8.2 magrittr_2.0.3   
#>  [5] reprex_2.0.1      evaluate_0.14     highr_0.9         stringi_1.7.4    
#>  [9] rlang_1.1.0       cli_3.6.1         rstudioapi_0.13   fs_1.5.2         
#> [13] R.utils_2.12.2    R.oo_1.25.0       vctrs_0.6.1       rmarkdown_2.11   
#> [17] styler_1.10.1     tools_4.1.1       stringr_1.4.0     glue_1.6.2       
#> [21] R.cache_0.16.0    purrr_0.3.4       xfun_0.39         yaml_2.2.1       
#> [25] fastmap_1.1.0     compiler_4.1.1    htmltools_0.5.5   knitr_1.35

Created on 2023-06-28 by the reprex package (v2.0.1)

olivroy commented 3 months ago

The way reactable can support grand_summary_rows() is via footer. https://glin.github.io/reactable/articles/examples.html#footers

summary_rows() could also be supported via groupBy and aggregate.

However, it would show on top instead of at the bottom. I may take this on with #1705 https://glin.github.io/reactable/articles/examples.html#aggregated-cell-rendering

https://github.com/rstudio/gt/pull/1171 has an option to display summary on top