modelsummary icon indicating copy to clipboard operation
modelsummary copied to clipboard

Blank table in Rmarkdown inline rendering with dark-themed Rstudio

Open kdzhang opened this issue 4 years ago • 6 comments

Hi, Thanks for the great package! I encountered the following problem when I tried to use this package.

When use dark mode in R-studio, the table does not show properly:

image

Use a light theme solves the problem:

image

Please copy the output of these commands:

library(modelsummary)
library(kableExtra)
sessionInfo()
> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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     

other attached packages:
[1] gt_0.2.2           kableExtra_1.3.4   modelsummary_0.7.0

loaded via a namespace (and not attached):
 [1] highr_0.8         compiler_4.0.5    pillar_1.4.7      tools_4.0.5       digest_0.6.27     checkmate_2.0.0  
 [7] gtable_0.3.0      evaluate_0.14     lifecycle_0.2.0   tibble_3.0.4      viridisLite_0.3.0 pkgconfig_2.0.3  
[13] rlang_0.4.10      rstudioapi_0.13   yaml_2.2.1        xfun_0.19         httr_1.4.2        stringr_1.4.0    
[19] dplyr_1.0.2       xml2_1.3.2        knitr_1.30        generics_0.1.0    vctrs_0.3.5       systemfonts_1.0.1
[25] grid_4.0.5        webshot_0.5.2     tidyselect_1.1.0  svglite_2.0.0     glue_1.4.2        R6_2.5.0         
[31] rmarkdown_2.5     tidyr_1.1.2       purrr_0.3.4       ggplot2_3.3.3     magrittr_2.0.1    backports_1.2.1  
[37] tables_0.9.6      scales_1.1.1      htmltools_0.5.0   ellipsis_0.3.1    rvest_0.3.6       colorspace_2.0-0 
[43] stringi_1.5.3     munsell_0.5.0     broom_0.7.5       crayon_1.3.4     

kdzhang avatar Apr 20 '21 21:04 kdzhang

It seems that some other packages also have this problem: https://github.com/glin/reactable/issues/21

kdzhang avatar Apr 20 '21 21:04 kdzhang

Hi @kdzhang , thanks a lot for reporting this issue!

Unfortunately, this one is out of my control, as this is a problem in an "upstream" package. The documentation may not be clear enough on this point, but modelsummary doesn't actually draw the tables itself. Instead, the package outsources the table drawing to one of four supported "backends": kableExtra, gt, flextable, and huxtable.

The default table backend is kableExtra, and if you try this Rmd file, you notice the same problem with a very minimalist kableExtra table:

---
title: "R Notebook"
output: html_document
---


```{r}
library(kableExtra)
dat <- data.frame(a = 1:2, b = 2:3)
kbl(dat)
```

I can see 2 main avenues for solutions:

  1. Use a different backend. In my attempts, I was able to replicate you problem with the default, but the other backends seem to work fine (although they background is white and a bit ugly with all of them). So you would type: modelsummary(mod, output="gt"), or you would set a global option at the top of your document to change the default backend in all of your subsquent calls: options(modelsummary_default="gt")
  2. Open an Issue on the kableExtra repository and hope that the maintainer has time for a solution. If you decide to open an issue, I think a minimal kableExtra-specific example like the one I posted above is probably best, and the link you found to the reactable repo seems useful (though I don't understand the exact problem after having read it).

vincentarelbundock avatar Apr 20 '21 21:04 vincentarelbundock

Hi @vincentarelbundock , thank you a lot for the very timely response! I think the gt solutions works well enough for me at this time.

And it seems that using kable instead of kbl will fix the display issue in your minimum example. I will report this to kableExtra team once I have a minute. Thanks a lot!

kdzhang avatar Apr 20 '21 21:04 kdzhang

There's a temporary solution here too, which involves injecting some extra CSS to the table displayed in RStudio https://github.com/haozhu233/kableExtra/issues/689#issuecomment-1170167006

andrewheiss avatar Jun 29 '22 15:06 andrewheiss

But it's still a kableExtra issue, not a modelsummary issue. It might be possible to permanently add the CSS override in kableExtra itself as long as it doesn't break output in light themes or non-RStudio editors, etc.

andrewheiss avatar Jun 29 '22 16:06 andrewheiss

Thanks for the follow up and the alternative solution! I'll just leave the issue open to make it easier to find in case someone else runs into it.

vincentarelbundock avatar Jun 29 '22 16:06 vincentarelbundock