Skip to content

Commit d88594f

Browse files
committed
Merge branch 'master' into setProps
2 parents 532eb56 + 6ca8cf5 commit d88594f

File tree

15 files changed

+106
-34
lines changed

15 files changed

+106
-34
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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## NEW FEATURES & IMPROVEMENTS
44

5-
* 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).
5+
* Upgraded to plotly.js v1.38.1. 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,20 @@
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

23+
24+
* 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()`.
25+
* In RStudio, `ggplotly()` was ignoring a specified `height`/`width` (see #1190).
26+
* `ggplotly()` now uses fixed heights for facet strips meaning that their height is still correct after a window resize (see #1265).
2227
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (see #1218).
2328
* 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)
29+
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (see #1242).
30+
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (see #1236).
2731

2832
# 4.7.1
2933

R/ggplotly.R

Lines changed: 23 additions & 10 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).
@@ -190,8 +193,8 @@ gg2list <- function(p, width = NULL, height = NULL,
190193
}
191194
# if a device (or RStudio) is already open, use the device size as default size
192195
if (!is.null(grDevices::dev.list()) || is_rstudio()) {
193-
width <- width %||% grDevices::dev.size("px")[1]
194-
height <- height %||% grDevices::dev.size("px")[2]
196+
width <- width %||% default(grDevices::dev.size("px")[1])
197+
height <- height %||% default(grDevices::dev.size("px")[2])
195198
}
196199
# open the device and make sure it closes on exit
197200
dev_fun(file = tempfile(), width = width %||% 640, height = height %||% 480)
@@ -1032,8 +1035,8 @@ gg2list <- function(p, width = NULL, height = NULL,
10321035
# If a trace isn't named, it shouldn't have additional hoverinfo
10331036
traces <- lapply(compact(traces), function(x) { x$name <- x$name %||% ""; x })
10341037

1035-
gglayout$width <- width
1036-
gglayout$height <- height
1038+
gglayout$width <- width %|D|% NULL
1039+
gglayout$height <- height %|D|% NULL
10371040
gglayout$barmode <- gglayout$barmode %||% "relative"
10381041

10391042
l <- list(
@@ -1239,21 +1242,31 @@ uniq <- function(x) {
12391242
make_strip_rect <- function(xdom, ydom, theme, side = "top") {
12401243
rekt <- rect2shape(theme[["strip.background"]])
12411244
stripTextX <- theme[["strip.text.x"]] %||% theme[["strip.text"]]
1242-
xTextSize <- unitConvert(stripTextX$size, "npc", "width")
1245+
topSize <-
1246+
mm2pixels(grid::convertHeight(stripTextX$margin[1], "mm")) +
1247+
mm2pixels(grid::convertHeight(stripTextX$margin[3], "mm")) +
1248+
mm2pixels(grid::convertHeight(grid::unit(stripTextX$size, units = "points"), "mm"))
12431249
stripTextY <- theme[["strip.text.y"]] %||% theme[["strip.text"]]
1244-
yTextSize <- unitConvert(stripTextY$size, "npc", "height")
1250+
rightSize <-
1251+
mm2pixels(grid::convertWidth(stripTextX$margin[2], "mm")) +
1252+
mm2pixels(grid::convertWidth(stripTextX$margin[4], "mm")) +
1253+
mm2pixels(grid::convertWidth(grid::unit(stripTextY$size, units = "points"), "mm"))
12451254
if ("right" %in% side) {
12461255
# x-padding should be accounted for in `layout.margin.r`
1247-
rekt$x0 <- xdom[2]
1248-
rekt$x1 <- xdom[2] + xTextSize
12491256
rekt$y0 <- ydom[1]
12501257
rekt$y1 <- ydom[2]
1258+
rekt$x0 <- 0
1259+
rekt$x1 <- rightSize
1260+
rekt$xanchor <- xdom[2]
1261+
rekt$xsizemode <- "pixel"
12511262
}
12521263
if ("top" %in% side) {
12531264
rekt$x0 <- xdom[1]
12541265
rekt$x1 <- xdom[2]
1255-
rekt$y0 <- ydom[2]
1256-
rekt$y1 <- ydom[2] + yTextSize
1266+
rekt$y0 <- 0
1267+
rekt$y1 <- topSize
1268+
rekt$yanchor <- ydom[2]
1269+
rekt$ysizemode <- "pixel"
12571270
}
12581271
list(rekt)
12591272
}

R/plotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ typedArrayPolyfill <- function() {
422422
# and bundle size at print time.
423423
plotlyMainBundle <- function() {
424424
htmltools::htmlDependency(
425-
"plotlyjs", "1.35.2",
425+
"plotlyjs", "1.38.1",
426426
src = depPath("plotlyjs"),
427427
script = "plotly-latest.min.js",
428428
stylesheet = "plotly-htmlwidgets.css"

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

R/sysdata.rda

8.58 KB
Binary file not shown.

R/utils.R

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,13 @@ supply_defaults <- function(p) {
349349
list(domain = geoDomain), p$x$layout[[p$x$layout$mapType]]
350350
)
351351
} else {
352-
axes <- if (is_type(p, "scatterternary")) {
353-
c("aaxis", "baxis", "caxis")
354-
} else if (is_type(p, "pie") || is_type(p, "parcoords") || is_type(p, "sankey") || is_type(p, "table")) {
355-
NULL
356-
} else {
357-
c("xaxis", "yaxis")
358-
}
352+
types <- vapply(p$x$data, function(tr) tr[["type"]] %||% "scatter", character(1))
353+
axes <- unlist(lapply(types, function(x) {
354+
grep("^[a-z]axis$", names(Schema$traces[[x]]$attributes), value = TRUE) %||% NULL
355+
}))
359356
for (axis in axes) {
360357
p$x$layout[[axis]] <- modify_list(
361-
list(domain = c(0, 1)), p$x$layout[[axis]]
358+
list(domain = c(0, 1), automargin = TRUE), p$x$layout[[axis]]
362359
)
363360
}
364361
}
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)

inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js

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

inst/htmlwidgets/plotly.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ HTMLWidgets.widget({
3333

3434
// Enable persistent selection when shift key is down
3535
// https://stackoverflow.com/questions/1828613/check-if-a-key-is-down
36-
var persistOnShift = function(e) {
36+
var persistOnShift = function(e) {
3737
if (!e) window.event;
3838
if (e.shiftKey) {
3939
x.highlight.persistent = true;
@@ -199,7 +199,7 @@ HTMLWidgets.widget({
199199
// https://www.mapbox.com/mapbox-gl-js/example/fitbounds/
200200
// so we do this manually...
201201
// TODO: make sure this triggers on a redraw and relayout as well as on initial draw
202-
var mapboxIDs = graphDiv._fullLayout._subplots.mapbox;
202+
var mapboxIDs = graphDiv._fullLayout._subplots.mapbox || [];
203203
for (var i = 0; i < mapboxIDs.length; i++) {
204204
var id = mapboxIDs[i];
205205
var mapOpts = x.layout[id] || {};
@@ -655,7 +655,7 @@ TraceManager.prototype.updateSelection = function(group, keys) {
655655
/ (2) highlight(selected = attrs_selected(...))
656656
*/
657657
// TODO: it would be neat to have a dropdown to dynamically specify these!
658-
$.extend(true, trace, this.highlight.selected, d.selected);
658+
$.extend(true, trace, this.highlight.selected);
659659

660660
// if it is defined, override color with the "dynamic brush color""
661661
if (d.marker) {
@@ -771,9 +771,8 @@ TraceManager.prototype.updateSelection = function(group, keys) {
771771

772772
if (tracesToDim.length > 0) {
773773
Plotly.restyle(this.gd, {"opacity": opacities}, tracesToDim);
774-
// this is an unfortunate consequence of the selected/unselected API
775-
// https://codepen.io/cpsievert/pen/opOawp
776-
Plotly.restyle(this.gd, {"unselected": {"marker": {"opacity": 1}}});
774+
// turn off the selected/unselected API
775+
Plotly.restyle(this.gd, {"selectedpoints": null});
777776
}
778777

779778
}

0 commit comments

Comments
 (0)