diff --git a/NEWS.md b/NEWS.md index 51c7b8dc74..0d1a395378 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,10 @@ * `highlight()` now supports `on="plotly_selecting"`, enabling client-side linked brushing via mouse click+drag (no mouse-up event required, as with `on="plotly_selected"`). (#1280) * `raster2uri()` supports nativeRaster objects. This enables nativeRaster support for the `annotation_raster()` geom (#2174, @zeehio). +* `plotlyOutput()`'s gains a `fill` argument which , allowing it have more flexible default sizing behavior, which will be useful in combination with `{bslib}`'s new `card()`. (#2192) + +* `plotlyOutput()` gains a new `fill` parameter. When `TRUE` (the default), the widget's container element is allowed to grow/shrink to fit it's parent container so long as that parent is opinionated about its height and has been marked with `htmltools::bindFillRole(x, container = TRUE)`. (#2198) + * The primary motivation for this is to allow plots to grow/shrink by default [inside `bslib::card_body_fill()`](https://rstudio.github.io/bslib/articles/cards.html#responsive-sizing) ## Bug fixes @@ -22,7 +26,6 @@ ## Improvements -* `plotlyOutput()`'s `height` and `width` now defaults to `NULL`, allowing it have more flexible default sizing behavior, which will be useful in combination with `{bslib}`'s new `card()`. (#2192) * `ggplotly()` does not issue warnings with `options(warnPartialMatchArgs = TRUE)` any longer. (#2046, thanks @bersbersbers) * `ggplotly()` does not issue warnings related to use of deprecated `tidyr::gather_()` in internals. (#2125, thanks @simonpcouch) diff --git a/R/shiny.R b/R/shiny.R index d5b8f2e78d..583b4492f8 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -17,14 +17,15 @@ #' @param env The environment in which to evaluate `expr`. #' @param quoted Is `expr` a quoted expression (with `quote()`)? This #' is useful if you want to save an expression in a variable. -#' +#' @param fill see [htmlwidgets::shinyWidgetOutput()] for explanation (requires +#' a recent version of htmlwidgets). #' @importFrom htmlwidgets shinyWidgetOutput #' @importFrom htmlwidgets shinyRenderWidget #' @name plotly-shiny #' #' @export -plotlyOutput <- function(outputId, width = NULL, height = NULL, - inline = FALSE, reportTheme = TRUE) { +plotlyOutput <- function(outputId, width = "100%", height = "400px", + inline = FALSE, reportTheme = TRUE, fill = !inline) { args <- list( outputId = outputId, name = "plotly", @@ -37,6 +38,9 @@ plotlyOutput <- function(outputId, width = NULL, height = NULL, if (is_installed("shiny", "1.4.0.9003") && is_installed("htmlwidgets", "1.5.2.9000")) { args$reportTheme <- reportTheme } + if (is_installed("htmlwidgets", "1.5.4.9001")) { + args$fill <- fill + } do.call(htmlwidgets::shinyWidgetOutput, args) } diff --git a/inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css b/inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css index 6e2ced6428..f35906d52c 100644 --- a/inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css +++ b/inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css @@ -1,8 +1,3 @@ -.plotly.html-widget { - width: 100%; - height: 400px; -} - /* just here so that plotly works correctly with ioslides. diff --git a/man/plotly-shiny.Rd b/man/plotly-shiny.Rd index 8d5ee7375d..bd7dd11e5f 100644 --- a/man/plotly-shiny.Rd +++ b/man/plotly-shiny.Rd @@ -8,8 +8,8 @@ \usage{ plotlyOutput( outputId, - width = NULL, - height = NULL, + width = "100\%", + height = "400px", inline = FALSE, reportTheme = TRUE ) @@ -37,6 +37,9 @@ version of shiny and htmlwidgets is available).} \item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This is useful if you want to save an expression in a variable.} + +\item{fill}{see \code{\link[htmlwidgets:htmlwidgets-shiny]{htmlwidgets::shinyWidgetOutput()}} for explanation (requires +a recent version of htmlwidgets).} } \description{ Output and render functions for using plotly within Shiny