Skip to content

Commit

Permalink
Set text color in R Notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
glin committed Mar 20, 2020
1 parent ae73161 commit 670de5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/reactable.R
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ renderReactable <- function(expr, env = parent.frame(), quoted = FALSE) {
#' @param ... Additional arguments.
#' @keywords internal
reactable_html <- function(id, style, class, ...) {
# Set text color in R Notebooks to prevent contrast issues when
# using a dark editor theme and htmltools 0.4.0.
if (isTRUE(getOption("rstudio.notebook.executing"))) {
style <- paste0("color: #333;", style)
}
htmltools::tagList(
# Necessary for RStudio viewer version < 1.2
reactR::html_dependency_corejs(),
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-reactable.R
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,14 @@ test_that("reactableOutput", {
expect_equal(output[[1]][[4]]$name, "div")
expect_equal(output[[1]][[4]]$attribs$id, "mytbl")
})

test_that("reactable_html", {
html <- reactable_html("id", "color: red", "class")
expect_equal(html[[4]], htmltools::tags$div(id = "id", class = "class", style = "color: red"))

# Text color should be set in R Notebooks
old <- options(rstudio.notebook.executing = TRUE)
on.exit(options(old))
html <- reactable_html(NULL, "color: red", NULL)
expect_equal(html[[4]], htmltools::tags$div(style = "color: #333;color: red"))
})

0 comments on commit 670de5b

Please sign in to comment.