Skip to content

Add fill argument to plotlyOutput() #2198

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
Oct 25, 2022
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
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
}

Expand Down
5 changes: 0 additions & 5 deletions inst/htmlwidgets/lib/plotlyjs/plotly-htmlwidgets.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.plotly.html-widget {
width: 100%;
height: 400px;
}

/*
just here so that plotly works
correctly with ioslides.
Expand Down
7 changes: 5 additions & 2 deletions man/plotly-shiny.Rd

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