Skip to content

Commit cc532e1

Browse files
committed
leverage new shiny output widget size reporting
1 parent 1b734af commit cc532e1

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

DESCRIPTION

Lines changed: 4 additions & 2 deletions
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.1),
3737
tidyr,
3838
hexbin,
3939
RColorBrewer,
@@ -66,7 +66,9 @@ Suggests:
6666
png,
6767
IRdisplay
6868
Remotes:
69-
tidyverse/ggplot2
69+
tidyverse/ggplot2,
70+
ramnathv/htmlwidgets,
71+
rstudio/shiny
7072
LazyData: true
7173
RoxygenNote: 6.0.1
7274
Roxygen: list(markdown = TRUE)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## NEW FEATURES & IMPROVEMENTS
44

55
* Upgraded to plotly.js v1.35.2. 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).
6+
* 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")`.
7+
* 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()`.
68
* The selection 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.
79
* 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)
810
* 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).

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)