Skip to content

Commit

Permalink
Use RStudio Page Viewer for full page widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Apr 11, 2018
1 parent fd4f976 commit 99d6cde
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
15 changes: 14 additions & 1 deletion R/htmlwidgets.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@ print.htmlwidget <- function(x, ..., view = interactive()) {

#' @export
print.suppress_viewer <- function(x, ..., view = interactive()) {
html_print(htmltools::as.tags(x, standalone=TRUE), viewer = if (view) browseURL)

viewer <- if (view) {
if (isTRUE(x$sizingPolicy$browser$external)) {
browseURL
} else if (!is.null(getOption("page_viewer"))) {
function(url) getOption("page_viewer")(url)
} else {
browseURL
}
} else {
NULL
}

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

Expand Down
8 changes: 6 additions & 2 deletions R/sizing.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#' @param browser.fill When displayed in a standalone web browser, automatically
#' size the widget to the browser dimensions (note that \code{browser.padding}
#' is still applied). Defaults to \code{FALSE}.
#' @param browser.external When displaying in a browser, always use an external
#' browser (via \code{browseURL()}). Defaults to \code{FALSE}, which will
#' result in the use of an internal browser within RStudio v1.1 and higher.
#' @param viewer.paneHeight Request that the RStudio Viewer be forced to a
#' specific height when displaying this widget.
#' @param viewer.suppress Never display the widget within the RStudio Viewer
Expand Down Expand Up @@ -80,7 +83,7 @@ sizingPolicy <- function(
viewer.padding = NULL, viewer.fill = TRUE, viewer.suppress = FALSE,
viewer.paneHeight = NULL,
browser.defaultWidth = NULL, browser.defaultHeight = NULL,
browser.padding = NULL, browser.fill = FALSE,
browser.padding = NULL, browser.fill = FALSE, browser.external = FALSE,
knitr.defaultWidth = NULL, knitr.defaultHeight = NULL,
knitr.figure = TRUE) {

Expand All @@ -100,7 +103,8 @@ sizingPolicy <- function(
defaultWidth = browser.defaultWidth,
defaultHeight = browser.defaultHeight,
padding = browser.padding,
fill = browser.fill
fill = browser.fill,
external = browser.external
),
knitr = list(
defaultWidth = knitr.defaultWidth,
Expand Down
9 changes: 7 additions & 2 deletions man/sizingPolicy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vignettes/develop_sizing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Here are the various options that can be specified within a sizing policy:
| **browser.defaultHeight** | The default height used to display the widget within a standalone web browser. |
| **browser.padding** | Padding around the widget when displayed in a standalone browser (defaults to 40 pixels). |
| **browser.fill** | When displayed in a standalone web browser, automatically size the widget to the browser dimensions (note that browser.padding is still applied). Defaults to FALSE. |
| **browser.external** | When displaying in a browser, always use an external browser (via `browseURL()`). Defaults to `FALSE`, which will result in the use of an internal browser within RStudio v1.1 and higher. |
| **knitr.defaultWidth** | The default width used to display the widget within documents generated by knitr (e.g. R Markdown). |
| **knitr.defaultHeight** | The default height used to display the widget within documents generated by knitr (e.g. R Markdown). |
| **knitr.figure** | Apply the default knitr fig.width and fig.height to the widget when it's rendered within R Markdown documents. Defaults to TRUE. |
Expand Down

0 comments on commit 99d6cde

Please sign in to comment.