Hi together,
I use the {gt} package for the first time and really enjoy it. While the table looked as epxected and complete in the Rstudio viewer pane and when run locally in any browser, I spend now most of the time figuring out how to save the table so it (a) contains the right fonts and (b) contains all ggplots and image files. And I failed so far.
Unfortunately, the code is too massive to upload it as a reprex but you can find the code on GitHub.
(Note: I keep this list updated every time a new suggestion comes in.)
What I tried:
gtsave(gt, "gt.html")
gtsave(gt, "gt.html", inline_css = TRUE)
gtsave(gt, "gt.png")
gtsave(gt, "gt.png", expand = 20)
gtsave(gt, "gt.png", expand = 20, delay = 1000)
- knit Rmd to html
- knit Rmd to html via
gt() %>% as_raw_html(inline_css = TRUE)
- export via
htmlWidgets::saveWidget(gt, "gt.html")
(gt objects seems not to be supported)
What happened:
-
The html files contains the correct fonts when saved with
inline_css = TRUE
but are missing the second ggplot column (I have two columns with visualizations), the one that contains way more complex and bigger plots. It is also missing the film posters (images via url) in the second column. -
The png files contains the images and almost all plots. Almost? Yes, from a certain row onwards the plots simply disappear (e.g. from row 83 onwards). Also, the emoji symbol is not rendered as expected. The
delay
seemed as a perfect candidate to solve it but it didn't change anything (same number of plots that are included/not included). -
The html inside the markdown report neither contains plots or images nor the correct fonts (fine in case of Overpass Mono and Bitter but not with the main font family Roboto Condensed - all of them are installed on my system and work locally, in the html and png). Also the font is bigger than specified in some of these columns and aspect ratios are completely ignored for plots and images. Emoji symbols are missing completely. When using the
as_raw_html()
the simple ggplots are all included but none of the web images nor any of the more complex ggplots. Again, some fonts are fine but some are not. Emojis are all missing.
Does anyone have an idea what's going on? Are the ggplot's simply too big and ambitious? Is there any other way to save it to html?
I am grateful for any hints and tipps!
Cheers, Cédric
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
system code page: 65001
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ragg_0.3.1 glue_1.4.1 here_0.1 gt_0.2.2 forcats_0.5.0 stringr_1.4.0
[7] dplyr_1.0.1 purrr_0.3.4 readr_1.3.1 tidyr_1.1.1 tibble_3.0.3 ggplot2_3.3.2.9000
[13] tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.16 haven_2.3.1 colorspace_1.4-1 vctrs_0.3.2 generics_0.0.2 htmltools_0.5.0
[8] yaml_2.2.1 blob_1.2.1 rlang_0.4.7 pillar_1.4.6 withr_2.2.0 DBI_1.1.0 dbplyr_1.4.4
[15] modelr_0.1.8 readxl_1.3.1 lifecycle_0.2.0 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_0.3.6
[22] knitr_1.29 fansi_0.4.1 broom_0.7.0 Rcpp_1.0.5 scales_1.1.1 backports_1.1.7 jsonlite_1.7.0
[29] systemfonts_0.2.3 fs_1.5.0 hms_0.5.3 packrat_0.5.0 digest_0.6.25 stringi_1.4.6 grid_4.0.2
[36] rprojroot_1.3-2 cli_2.0.2 tools_4.0.2 magrittr_1.5 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1
[43] xml2_1.3.2 reprex_0.3.0 lubridate_1.7.9 assertthat_0.2.1 httr_1.4.2 rstudioapi_0.11 R6_2.4.1
[50] compiler_4.0.2