Skip to content

Commit 59b2e24

Browse files
authored
Merge pull request #1219 from ropensci/reportSize
leverage new shiny output widget size reporting
2 parents d6823a5 + f747541 commit 59b2e24

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Imports:
3333
viridisLite,
3434
base64enc,
3535
htmltools,
36-
htmlwidgets (>= 0.9),
36+
htmlwidgets (>= 1.2),
3737
tidyr,
3838
hexbin,
3939
RColorBrewer,

NEWS.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Upgraded to plotly.js v1.37.0. A _huge_ amount of features and improvements have been made since v1.29.2 (i.e., the version included in the last CRAN release of the R package - v4.7.1). Highlights include a complete re-write of `scattergl` to make it nearly feature complete with `scatter`, localization of text rendering (i.e., international translations), and two new trace types (`violin` & `table`). Read more about the v1.32.0 release [here](https://codeburst.io/notes-from-the-latest-plotly-js-release-b035a5b43e21) and the complete list of changes [here](https://github.com/plotly/plotly.js/releases).
66
* Support for **sf** (simple feature) data structures was added to `plot_ly()`, `plot_mapbox()`, and `plot_geo()` (via the new `add_sf()` function). See [this blog post](https://blog.cpsievert.me/2018/03/30/visualizing-geo-spatial-data-with-sf-and-plotly) for an overview.
77
* New "special arguments" `stroke`, `strokes`, `alpha_stroke`, `span`, and `spans` were added for easier control over the stroke (i.e., outline) appearance of various (filled) graphical marks. For an overview, see the **sf** blog post linked to in the bullet point above and the new package demos (list all demos with `demo(package = "plotly")`).
8+
* One may now inform `ggplotly()` about the relevant **shiny** output size via `session$clientData`. This ensures `ggplotly()` sizing is closer to **ggplot2** sizing, even on window resize. For an example, run `plotly_example("shiny", "ggplotly_sizing")`.
89
* The selection (i.e., linked-brushing) mode can now switch from 'transient' to 'persistent' by holding the 'shift' key. It's still possible to _force_ persistent selection by setting `persistent = TRUE` in `highlight()`, but `persistent = FALSE` (the default) is now recommended since it allows one to switch between [persistent/transient selection](https://plotly-book.cpsievert.me/linking-views-without-shiny.html#transient-versus-persistent-selection) in the browser, rather than at the command line.
910
* Instead of an error, `ggplotly(NULL, "message")` and `plotly_build(NULL, "message")` now returns `htmltools::div("message")`, making it easier to relay messages in shiny when data isn't yet ready to plot (see #1116)
1011
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (see #1205).
@@ -13,17 +14,18 @@
1314

1415
* The `color` argument now maps to `fillcolor`, making it much easier to use polygon fills to encode data values (e.g., choropleth maps). For backwards-compatibilty reasons, when `color` maps to `fillcolor`, `alpha` defaults to 0.5 (instead of 1). For an example, `plot_mapbox(mn_res, color = ~INDRESNAME)` or `plot_mapbox(mn_res, split = ~INDRESNAME, color = ~AREA, showlegend = FALSE, stroke = I("black"))`.
1516
* The `color` argument no longer automatically add `"markers"` to the `mode` attribute for scatter/scattergl trace types. Those who wish to have the old behavior back, should add `"markers"` to the `mode` explicity (e.g., change `plot_ly(economics, x = ~pce, y = ~pop, color = ~as.numeric(date), mode = "lines")` to `plot_ly(economics, x = ~pce, y = ~pop, color = ~as.numeric(date), mode = "lines+markers")`).
16-
* The `size` argument now informs a default [error_[x/y].width](https://plot.ly/r/reference/#scatter-error_x-width) (and `span` informs [error_[x/y].thickness](https://plot.ly/r/reference/#scatter-error_x-thickness)). Note you can override the default by specifying directly (e.g. `plot_ly(x = 1:10, y = 1:10, size = I(10), error_x = list(value = 5, width = 0))`)
17+
* The `size` argument now informs a default [error_[x/y].width](https://plot.ly/r/reference/#scatter-error_x-width) (and `span` informs [error_[x/y].thickness](https://plot.ly/r/reference/#scatter-error_x-thickness)). Note you can override the default by specifying directly (e.g. `plot_ly(x = 1:10, y = 1:10, size = I(10), error_x = list(value = 5, width = 0))`).
1718
* `layout.showlegend` now defaults to `TRUE` for a *single* pie trace. This is a more sensible default and matches pure plotly.js behavior.
1819
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (see #985).
1920

2021
## BUG FIXES
2122

2223
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (see #1218).
2324
* Fixed algorithm for coercing the proposed layout to the plot schema (see #1156).
24-
* grid conversions in `ggplotly()` weren't respected a specified `height`/`width` in RStudio (see #1190).
25-
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE`, see #1242.
26-
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (see #1236)
25+
* The default `height`/`width` that `ggplotly()` assumes is now more consistently correct in various context, but it also now requires access to one of the following devices: `Cairo::Cairo()`, `png()`, or `jpg()`.
26+
* In RStudio, `ggplotly()` was ignoring `height`/`width` (see #1190).
27+
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (see #1242).
28+
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (see #1236).
2729

2830
# 4.7.1
2931

R/ggplotly.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#' graphics device (if no device is open, width/height of a new (off-screen)
88
#' device defaults to 640/480). In other words, `height` and
99
#' `width` must be specified at runtime to ensure sizing is correct.
10+
#' For examples on how to specify the output container's `height`/`width` in a
11+
#' shiny app, see `plotly_example("shiny", "ggplotly_sizing")`.
12+
#'
1013
#'
1114
#' @param p a ggplot object.
1215
#' @param width Width of the plot in pixels (optional, defaults to automatic sizing).

R/shiny.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px",
2727
width = width,
2828
height = height,
2929
inline = inline,
30-
package = "plotly"
30+
package = "plotly",
31+
reportSize = TRUE
3132
)
3233
}
3334

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library(shiny)
2+
library(plotly)
3+
4+
ui <- fluidPage(
5+
plotlyOutput("pid")
6+
)
7+
8+
server <- function(input, output, session, ...) {
9+
10+
# to relay the height/width of the plot's container, we'll query this
11+
# session's client data http://shiny.rstudio.com/articles/client-data.html
12+
cdata <- session$clientData
13+
14+
output$pid <- renderPlotly({
15+
p <- ggplot(iris) +
16+
geom_point(aes(Sepal.Length, Sepal.Width)) +
17+
facet_wrap(~Species)
18+
19+
ggplotly(p, width = cdata$output_pid_width, height = cdata$output_pid_height)
20+
})
21+
22+
}
23+
24+
shinyApp(ui, server)

man/ggplotly.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)