Using gt() function to generate tables in a report file with Rmarkdown in Rstudio (knitting to HTML).
ISSUE:
When adding gt_plt_bar() to show a bar chart inside the table, these resulting tables can only be knitted in the Rmarkdown file while not in a for loop. Something along the HTML code gets disrupted since there is some printing HTML code happening when failing to knit (see section "_Normal table WITH gt_pltbar() inside a for loop" of the example below).
Reproducible example
Here is a reproducible example for Rmarkdown (you can copy&paste the whole code into your own Rmarkdown).
Description
Using
gt()
function to generate tables in a report file with Rmarkdown in Rstudio (knitting to HTML).ISSUE: When adding
gt_plt_bar()
to show a bar chart inside the table, these resulting tables can only be knitted in the Rmarkdown file while not in afor
loop. Something along the HTML code gets disrupted since there is some printing HTML code happening when failing to knit (see section "_Normal table WITH gt_pltbar() inside a for loop" of the example below).Reproducible example
Here is a reproducible example for Rmarkdown (you can copy&paste the whole code into your own Rmarkdown).
title: "gt_plt_bar_ISSUE" output: html_document date: "2023-05-18"
Test for gt_plt_bar() issue
Normal table
Normal table WITH
gt_plt_bar()
Normal table inside a
for
loopNormal table WITH
gt_plt_bar()
inside afor
loopInside a
for
loop WITHgt_plt_bar()
(withoutprint()
)Expected result
Tables should be able to be printed inside a loop without disrupting the HTML knitting.
Session info
Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached): [1] rstudioapi_0.14 xml2_1.3.3 knitr_1.42 magrittr_2.0.3 gt_0.9.0
[6] tidyselect_1.2.0 munsell_0.5.0 colorspace_2.1-0 R6_2.5.1 rlang_1.1.0
[11] fastmap_1.1.1 fansi_1.0.4 dplyr_1.1.1 tools_4.2.3 DT_0.27
[16] grid_4.2.3 trtemplate_1.0.0 gtable_0.3.3 xfun_0.38 utf8_1.2.3
[21] cli_3.6.1 htmltools_0.5.5 yaml_2.3.7 digest_0.6.31 tibble_3.2.1
[26] lifecycle_1.0.3 ggplot2_3.4.2 htmlwidgets_1.6.2 vctrs_0.6.1 glue_1.6.2
[31] evaluate_0.20 rmarkdown_2.21 pillar_1.9.0 compiler_4.2.3 generics_0.1.3
[36] scales_1.2.1 pkgconfig_2.0.3