vincentarelbundock / modelsummary

Beautiful and customizable model summaries in R.
http://modelsummary.com
Other
912 stars 75 forks source link

Blank table in Rmarkdown inline rendering with dark-themed Rstudio #269

Closed kdzhang closed 7 months ago

kdzhang commented 3 years ago

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 commented 3 years ago

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

vincentarelbundock commented 3 years ago

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](https://github.com/haozhu233/kableExtra) 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).
kdzhang commented 3 years ago

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!

andrewheiss commented 2 years ago

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 commented 2 years ago

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.

vincentarelbundock commented 2 years ago

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.

kevinmcdermott062 commented 1 year ago

I have the same issue when using knitr::kable(). If you look closely you can see the output, but it looks like a negative. If I click to view the table in a new window, the text becomes visible. image image

using gt(dff), the table renders as it should. image

andrewheiss commented 1 year ago

Yeah, it's an issue with kableExtra. There's a workaround for it here: https://github.com/haozhu233/kableExtra/issues/689#issuecomment-1170167006 (I actually have that print.kableExtra() function stored as a keyboard snippet in RStudio so I can run it whenever I need to look at kableExtra-based tables)

andrewheiss commented 1 year ago

Ah and there might be a weird inconsistent bug in RStudio about this.

With the latest daily version of RStudio, and with no other packages loaded, it should look like this with knitr::kable(), with white text:

image

kableExtra::kable() should show the same thing:

image

kableExtra::kbl() shows everything with a white background:

image

And with the custom print.kableExtra() function loaded and with kable_styling(), it's correct:

image

However, with slightly older versions of RStudio, knitr::kable() shows up incorrectly…

image

…but once you switch to a different tab in the editor window and switch back to the original document, or move the RStudio window to a different screen, or do something else to trigger a refresh of the document, the text shows up correctly, which is bizarre

image
kevinmcdermott062 commented 1 year ago

I believe I'm using the latest version of RStudio, at least that is what RStudio reports when I check for updates. As my previous post shows...this RStudio version seems to have a rendering issue. image

andrewheiss commented 1 year ago

Does switching to a different tab and coming back to the Rmd file update it for you? In the daily builds for version 2022.03, forcing a document refresh will make the text show correctly

image
andrewheiss commented 1 year ago

I'm opening an issue at RStudio's repository now

andrewheiss commented 1 year ago

https://github.com/rstudio/rstudio/issues/12658

vincentarelbundock commented 1 year ago

Thanks a lot @andrewheiss . I don't use Rstudio, so I'm not confronted with this issue regularly, and it's kinda hard for me to diagnose, so this is very helpful.

kevinmcdermott062 commented 1 year ago

Does switching to a different tab and coming back to the Rmd file update it for you? In the daily builds for version 2022.03, forcing a document refresh will make the text show correctly image

Yes, I just double checked...Same result if I select to 'open in a new window', the text eventually is displayed. Until I actually take this next step, all I can barely makeout is a 'negative' of the text otherwise.

vincentarelbundock commented 7 months ago

fixed upstream in kableExtra.

Upcoming modelsummary 2.0.0 will use tinytable as default (breaking change), so this is no longer as relevant.