Skip to content

Commit 36e2928

Browse files
authored
Add reportTheme argument to plotlyOutput() for reporting CSS styles (#1802)
* Add reportTheme argument to plotlyOutput() for reporting CSS styles * update news, document, and add htmlwidgets to remotes
1 parent 4357e2c commit 36e2928

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ LazyData: true
7878
RoxygenNote: 7.1.0
7979
Encoding: UTF-8
8080
Roxygen: list(markdown = TRUE)
81-
Remotes: rstudio/thematic
81+
Remotes:
82+
rstudio/thematic,
83+
ramnathv/htmlwidgets

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## NEW FEATURES
88

9-
* `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).
9+
* `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).
1010

1111
## IMPROVEMENTS
1212

R/shiny.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#' height is computed with HTML/CSS.
1212
#' @param inline use an inline (`span()`) or block container
1313
#' (`div()`) for the output
14+
#' @param reportTheme whether or not to report CSS styles (if a sufficient
15+
#' version of shiny and htmlwidgets is available).
1416
#' @param expr An expression that generates a plotly
1517
#' @param env The environment in which to evaluate `expr`.
1618
#' @param quoted Is `expr` a quoted expression (with `quote()`)? This
@@ -22,8 +24,8 @@
2224
#'
2325
#' @export
2426
plotlyOutput <- function(outputId, width = "100%", height = "400px",
25-
inline = FALSE) {
26-
htmlwidgets::shinyWidgetOutput(
27+
inline = FALSE, reportTheme = TRUE) {
28+
args <- list(
2729
outputId = outputId,
2830
name = "plotly",
2931
width = width,
@@ -32,6 +34,10 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px",
3234
package = "plotly",
3335
reportSize = TRUE
3436
)
37+
if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.1.9001")) {
38+
args$reportTheme <- reportTheme
39+
}
40+
do.call(htmlwidgets::shinyWidgetOutput, args)
3541
}
3642

3743
#' @rdname plotly-shiny

R/utils.R

+9
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,15 @@ try_library <- function(pkg, fun = NULL) {
11371137
"Please install and try again.", call. = FALSE)
11381138
}
11391139

1140+
# a la shiny:::is_available
1141+
is_available <- function(package, version = NULL) {
1142+
installed <- nzchar(system.file(package = package))
1143+
if (is.null(version)) {
1144+
return(installed)
1145+
}
1146+
installed && isTRUE(utils::packageVersion(package) >= version)
1147+
}
1148+
11401149
# similar logic to rstudioapi::isAvailable()
11411150
is_rstudio <- function() {
11421151
identical(.Platform$GUI, "RStudio")

man/plotly-shiny.Rd

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotly_IMAGE.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)