Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matthewgson opened this issue Feb 10, 2022 · 6 comments
Closed

Comments

@matthewgson
Copy link

Hi, I'm having an issue exactly described here :
vincentarelbundock/modelsummary#269

The author seems to have solved the issue by using kable() instead of kbl(), but forgot to raise it here.

@zaynesember
Copy link

Also have been having this issue. So frustrating!

@andrewheiss
Copy link

This continues to be an issue, but there's a temporary workaround here. You can inject color: black; into the inline CSS for the kableExtra table by modifying the existing print.kableExtra() function:

print.kableExtra <- function (x, ...) {
  view_html <- getOption("kableExtra_view_html", TRUE)
  if (view_html & interactive()) {
    dep <- list(
      rmarkdown::html_dependency_jquery(), 
      rmarkdown::html_dependency_bootstrap(theme = "cosmo"), 
      kableExtra::html_dependency_kePrint(), 
      kableExtra::html_dependency_lightable()
    )
    
    x <- sub('style="', 'style="color: black; ', as.character(x), fixed = TRUE)
        
    html_kable <- htmltools::browsable(
      htmltools::HTML(
        as.character(x), 
        "<script type=\"text/x-mathjax-config\">MathJax.Hub.Config({tex2jax: {inlineMath: [[\"$\",\"$\"]]}})</script><script async src=\"https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>"
      )
    )
    htmltools::htmlDependencies(html_kable) <- dep
    class(html_kable) <- "shiny.tag.list"
    print(html_kable)
  }
  else {
    cat(as.character(x))
  }
}

This fixes things when working with a dark theme.

Before (using the Monokai theme in RStudio):

image

After running new print.kableExtra() (again, with the Monokai theme):

image

You can include the new print.kableExtra() in ~/.Rprofile so that you have access to it in every new R session (though it'll show up in the environment and clutter it up 🤷‍♂️)

This is a good temporary solution, but it would be cool to someday have style="color: black;" automatically built in

@andrewheiss
Copy link

@haozhu233 Would adding x <- sub('style="', 'style="color: black; ', as.character(x), fixed = TRUE) to line 11 in print.kableExtra() here…

kableExtra/R/print.R

Lines 2 to 23 in a6af5c0

print.kableExtra <- function(x, ...) {
view_html <- getOption("kableExtra_view_html", TRUE)
if (view_html & interactive()) {
dep <- list(
rmarkdown::html_dependency_jquery(),
rmarkdown::html_dependency_bootstrap(theme = "cosmo"),
html_dependency_kePrint(),
html_dependency_lightable()
)
html_kable <- htmltools::browsable(
htmltools::HTML(
as.character(x),
'<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [["$","$"]]}})</script><script async src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'
)
)
htmlDependencies(html_kable) <- dep
class(html_kable) <- "shiny.tag.list"
print(html_kable)
} else {
cat(as.character(x))
}
}

…mess things up in light themes or other non-RStudio editors, or would that be a safe change? I'd be happy to open a PR if it's safe.

Thanks!

@vincentarelbundock
Copy link
Collaborator

FWIW, I think a "cleaner" fix would be to add this code on line 267 of kable_styling.R

  # issue 689: invisible font in Rstudio dark theme
  flag <- tryCatch(rstudioapi::getThemeInfo()$dark, error = function(e) FALSE)
  if (isTRUE(flag)) {
    kable_xml_style <- c(kable_xml_style, "color: black;")
  }

I'd be curious if anyone could try it and let me know if it works on their computer as well. You can try my fork by calling:

remotes::install_github("vincentarelbundock/kableExtra@dev")

Restart R completely, and try again.

@andrewheiss
Copy link

Oh neat, that fixes it!

image

@vincentarelbundock
Copy link
Collaborator

Fixed here: #768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants