From 697a662a6ddf45f31f4b48d9804a97f672c107ee Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 6 May 2020 17:52:40 -0500 Subject: [PATCH 1/2] Add reportTheme argument to plotlyOutput() for reporting CSS styles --- R/shiny.R | 10 ++++++++-- R/utils.R | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/R/shiny.R b/R/shiny.R index e4187eb680..26fba730dd 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -11,6 +11,8 @@ #' height is computed with HTML/CSS. #' @param inline use an inline (`span()`) or block container #' (`div()`) for the output +#' @param reportTheme whether or not to report CSS styles (if a sufficient +#' version of shiny and htmlwidgets is available). #' @param expr An expression that generates a plotly #' @param env The environment in which to evaluate `expr`. #' @param quoted Is `expr` a quoted expression (with `quote()`)? This @@ -22,8 +24,8 @@ #' #' @export plotlyOutput <- function(outputId, width = "100%", height = "400px", - inline = FALSE) { - htmlwidgets::shinyWidgetOutput( + inline = FALSE, reportTheme = TRUE) { + args <- list( outputId = outputId, name = "plotly", width = width, @@ -32,6 +34,10 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px", package = "plotly", reportSize = TRUE ) + if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.1.9001")) { + args$reportTheme <- reportTheme + } + do.call(htmlwidgets::shinyWidgetOutput, args) } #' @rdname plotly-shiny diff --git a/R/utils.R b/R/utils.R index 5161d93491..67b73e79f4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1137,6 +1137,15 @@ try_library <- function(pkg, fun = NULL) { "Please install and try again.", call. = FALSE) } +# a la shiny:::is_available +is_available <- function(package, version = NULL) { + installed <- nzchar(system.file(package = package)) + if (is.null(version)) { + return(installed) + } + installed && isTRUE(utils::packageVersion(package) >= version) +} + # similar logic to rstudioapi::isAvailable() is_rstudio <- function() { identical(.Platform$GUI, "RStudio") From 20428ba7d5ebf3f9e1738f8f0647e28d9d333b78 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 26 Jun 2020 10:55:15 -0500 Subject: [PATCH 2/2] update news, document, and add htmlwidgets to remotes --- DESCRIPTION | 4 +++- NEWS.md | 2 +- man/plotly-shiny.Rd | 11 ++++++++++- man/plotly_IMAGE.Rd | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9fc57b87e1..a3d68e6c94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -78,4 +78,6 @@ LazyData: true RoxygenNote: 7.1.0 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -Remotes: rstudio/thematic +Remotes: + rstudio/thematic, + ramnathv/htmlwidgets diff --git a/NEWS.md b/NEWS.md index bfc705abfe..4ee465b351 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,7 @@ ## NEW FEATURES -* `ggplotly()` now works well with the [**thematic** package](https://rstudio.github.io/thematic). That is, it can now correctly translate **ggplot2** styling that derives from **thematic** (#1801). +* `ggplotly()` now works well with the [**thematic** package](https://rstudio.github.io/thematic). That is, it can now correctly translate **ggplot2** styling that derives from **thematic**. Note that, in order to use **thematic**'s auto theming in Shiny with `ggplotly()`, you need **shiny** v1.5.0 (or higher) and **htmlwidgets** v1.5.1.9001 (or higher). Relatedly, if these versions are available, one may now also call `getCurrentOutputInfo()` inside `renderPlotly()` to get CSS styles of the output container (#1801 and #1802). ## IMPROVEMENTS diff --git a/man/plotly-shiny.Rd b/man/plotly-shiny.Rd index 2f61dd6f00..167a1c9174 100644 --- a/man/plotly-shiny.Rd +++ b/man/plotly-shiny.Rd @@ -6,7 +6,13 @@ \alias{renderPlotly} \title{Shiny bindings for plotly} \usage{ -plotlyOutput(outputId, width = "100\%", height = "400px", inline = FALSE) +plotlyOutput( + outputId, + width = "100\%", + height = "400px", + inline = FALSE, + reportTheme = TRUE +) renderPlotly(expr, env = parent.frame(), quoted = FALSE) } @@ -22,6 +28,9 @@ height is computed with HTML/CSS.} \item{inline}{use an inline (\code{span()}) or block container (\code{div()}) for the output} +\item{reportTheme}{whether or not to report CSS styles (if a sufficient +version of shiny and htmlwidgets is available).} + \item{expr}{An expression that generates a plotly} \item{env}{The environment in which to evaluate \code{expr}.} diff --git a/man/plotly_IMAGE.Rd b/man/plotly_IMAGE.Rd index 42f732054c..96337f9257 100644 --- a/man/plotly_IMAGE.Rd +++ b/man/plotly_IMAGE.Rd @@ -27,7 +27,7 @@ plotly_IMAGE( \item{out_file}{A filename for writing the image to a file.} -\item{...}{arguments passed onto \code{httr::POST}} +\item{...}{arguments passed onto \code{httr::RETRY}} } \description{ The images endpoint turns a plot (which may be given in multiple forms)