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

Allow passing background down from print.htmlwidget to html_print #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/htmlwidgets.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @export
print.htmlwidget <- function(x, ..., view = interactive()) {
print.htmlwidget <- function(x, ..., view = interactive(), background = "white") {

# if we have a viewer then forward viewer pane height (if any)
viewer <- getOption("viewer")
Expand All @@ -23,14 +23,15 @@ print.htmlwidget <- function(x, ..., view = interactive()) {
}

# call html_print with the viewer
html_print(htmltools::as.tags(x, standalone=TRUE), viewer = if (view) viewerFunc)
html_print(htmltools::as.tags(x, standalone=TRUE),
background = background, viewer = if (view) viewerFunc)

# return value
invisible(x)
}

#' @export
print.suppress_viewer <- function(x, ..., view = interactive()) {
print.suppress_viewer <- function(x, ..., background = "white", view = interactive()) {

viewer <- if (view) {
if (isTRUE(x$sizingPolicy$browser$external)) {
Expand All @@ -44,7 +45,7 @@ print.suppress_viewer <- function(x, ..., view = interactive()) {
NULL
}

html_print(htmltools::as.tags(x, standalone=TRUE), viewer = viewer)
html_print(htmltools::as.tags(x, standalone=TRUE), background = background, viewer = viewer)
invisible(x)
}

Expand Down Expand Up @@ -307,7 +308,6 @@ widget_data <- function(x, id, ...){
#' @param preRenderHook A function to be run on the widget, just prior to
#' rendering. It accepts the entire widget object as input, and should return
#' a modified widget object.
#'
#' @return An object of class \code{htmlwidget} that will intelligently print
#' itself into HTML in a variety of contexts including the R console, within R
#' Markdown documents, and within Shiny output bindings.
Expand Down