davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
561 stars 81 forks source link

Flextable different borders in outputs from RStudio and rmarkdown HTML #587

Closed marcos-lozalva closed 11 months ago

marcos-lozalva commented 12 months ago

Hello

I'm using flextable() to include tables in a report in HTML in Rmarkdown. The problem is that the table in the ouput of Rstudio is OK but when I run the code in Rmarkdown, the vertical borders turn to color white and the horizontal lines turn to double line. In addition, I'm not able to center the table in the HTML report, could you help me? Thank you very much

This is my code:

  set_flextable_defaults(border.color = "#3a7399",
                         font.family = "Roboto",
                         font.size = 11,
                         font.color = "#666666",
                         decimal.mark = ",", big.mark = ".",
                         text.align = "right")

  data.sindrom3 <- set_header_df(data.sindrom3, mapping = df, key = "col_keys" ) %>% 
    merge_v(part = "header", j = 1) %>% 
    merge_h(part = "header", i = 1) %>% 
    theme_vanilla() %>% 
    bg(., bg = "#D9E7EF", part = "header") %>% 
    bg(., i = if(d %in% "ira1") seq(2,length(unique(data.sindrom2$ccaa)), by=2) 
       else if (d %in%  "ira2") seq(2,length(unique(data.sindrom2$ccaa)), by=2), 
       bg = "#D9E7EF50",  part = "body") %>% 
    bg(., i = length(unique(data.sindrom2$ccaa)),  bg = "#D9E7EF", part = "body") %>% 
    align(i = 1, align = "center", part = "header") %>% 
    bold(., i = if(d %in% "ira1") length(unique(data.sindrom2$ccaa)) 
         else if (d %in%  "ira2") length(unique(data.sindrom2$ccaa))) %>% 
    bold(., j = 1) %>% 
    autofit()

VIEWER IN RSTUDIO (ok): Screenshot 2023-11-15 at 09-13-03 https __rstudio isciii es

HTML RMARKDOWN (wrong borders and table not centered): Captura de pantalla 2023-11-15 090739

sysname release version nodename "Linux" "4.18.0-425.13.1.el8_7.x86_64" "#1 SMP Thu Feb 2 13:01:45 EST 2023"

davidgohel commented 12 months ago

can you post the sessionInfo() please and the R Markdown?

When submitting a new issue:

marcos-lozalva commented 12 months ago

sorry David I forgot it!

but finally I´ve found a solution. I just had to install a previous version of flextable (0.8.0), because the dependencies (especially gdtools) are installed in the system library, and every time I tried to install flextable() it threw an error saying that the dependencies were loaded and I needed to update them. The problem is that I'm using an R corporative web and I have no permissions to write in the system library. I hope you have understood me. I don't know if there is a simpler solution.

R version 4.1.2 (2021-11-01) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux 8.9 (Ootpa)

Matrix products: default BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] officer_0.6.3 flextable_0.8.0 devtools_2.4.5 cli_3.6.1 usethis_2.2.2

loaded via a namespace (and not attached): [1] xfun_0.28 remotes_2.4.2 purrr_0.3.4 miniUI_0.1.1.1 htmltools_0.5.7 yaml_2.2.1 base64enc_0.1-3 rlang_1.1.2
[9] pkgbuild_1.3.1 urlchecker_1.0.1 later_1.3.0 glue_1.6.2 gdtools_0.2.3 sessioninfo_1.2.2 uuid_1.0-3 lifecycle_1.0.4
[17] plyr_1.8.6 stringr_1.4.0 ragg_1.2.2 zip_2.2.0 htmlwidgets_1.5.4 memoise_2.0.1 evaluate_0.23 knitr_1.36
[25] callr_3.7.3 fastmap_1.1.1 httpuv_1.6.7 ps_1.7.5 Rcpp_1.0.7 xtable_1.8-4 openssl_1.4.5 promises_1.2.0.1 [33] cachem_1.0.6 pkgload_1.3.3 mime_0.12 fs_1.5.2 systemfonts_1.0.3 textshaping_0.3.6 askpass_1.1 digest_0.6.33
[41] stringi_1.7.6 processx_3.8.2 shiny_1.7.5.1 grid_4.1.2 tools_4.1.2 magrittr_2.0.3 pacman_0.5.1 profvis_0.3.8
[49] crayon_1.4.2 ellipsis_0.3.2 rsconnect_0.8.25 data.table_1.14.2 xml2_1.3.3 prettyunits_1.1.1 rmarkdown_2.11 rstudioapi_0.13
[57] R6_2.5.1 compiler_4.1.2

davidgohel commented 11 months ago

Hi

Unfortunately, there is no solution (at least in my mind). If you can not install update, you're doomed to use the installed version and that's it :/

Usually, users can install things in their home directory but it also means users must have access to gcc, etc. I don't know what your IT allows and does not allow. From my experience, this kind of investigations with IT could take days or weeks and is out of the scope of the support we can bring here.

I hope you'll understand.

KR

github-actions[bot] commented 5 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.