Skip to content

Commit 2db78b7

Browse files
authored
Add fill argument to plotlyOutput() (#2198)
* Revert "plotlyOutput()'s width and height now default to NULL (and default CSS sizing is provided using a non-inline style) (#2192)" This reverts commit 2062096. * Add fill argument to plotlyOutput()
1 parent c95a20f commit 2db78b7

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

NEWS.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
* `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)
1111
* `raster2uri()` supports nativeRaster objects. This enables nativeRaster support for
1212
the `annotation_raster()` geom (#2174, @zeehio).
13+
* `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)
14+
15+
* `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)
16+
* 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)
1317

1418
## Bug fixes
1519

@@ -22,7 +26,6 @@
2226

2327
## Improvements
2428

25-
* `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)
2629
* `ggplotly()` does not issue warnings with `options(warnPartialMatchArgs = TRUE)` any longer. (#2046, thanks @bersbersbers)
2730
* `ggplotly()` does not issue warnings related to use of deprecated `tidyr::gather_()` in internals. (#2125, thanks @simonpcouch)
2831

R/shiny.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
#' @param env The environment in which to evaluate `expr`.
1818
#' @param quoted Is `expr` a quoted expression (with `quote()`)? This
1919
#' is useful if you want to save an expression in a variable.
20-
#'
20+
#' @param fill see [htmlwidgets::shinyWidgetOutput()] for explanation (requires
21+
#' a recent version of htmlwidgets).
2122
#' @importFrom htmlwidgets shinyWidgetOutput
2223
#' @importFrom htmlwidgets shinyRenderWidget
2324
#' @name plotly-shiny
2425
#'
2526
#' @export
26-
plotlyOutput <- function(outputId, width = NULL, height = NULL,
27-
inline = FALSE, reportTheme = TRUE) {
27+
plotlyOutput <- function(outputId, width = "100%", height = "400px",
28+
inline = FALSE, reportTheme = TRUE, fill = !inline) {
2829
args <- list(
2930
outputId = outputId,
3031
name = "plotly",
@@ -37,6 +38,9 @@ plotlyOutput <- function(outputId, width = NULL, height = NULL,
3738
if (is_installed("shiny", "1.4.0.9003") && is_installed("htmlwidgets", "1.5.2.9000")) {
3839
args$reportTheme <- reportTheme
3940
}
41+
if (is_installed("htmlwidgets", "1.5.4.9001")) {
42+
args$fill <- fill
43+
}
4044
do.call(htmlwidgets::shinyWidgetOutput, args)
4145
}
4246

inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.plotly.html-widget {
2-
width: 100%;
3-
height: 400px;
4-
}
5-
61
/*
72
just here so that plotly works
83
correctly with ioslides.

man/plotly-shiny.Rd

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

0 commit comments

Comments
 (0)