8000 Add reportTheme argument to plotlyOutput() for reporting CSS styles by cpsievert · Pull Request #1802 · plotly/plotly.R · GitHub
[go: up one dir, main page]

Skip to content

Add reportTheme argument to plotlyOutput() for reporting CSS styles #1802

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

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion man/plotly-shiny.Rd

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

2 changes: 1 addition & 1 deletion man/plotly_IMAGE.Rd

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

0