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 1 commit
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: 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 BE47 +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
0