Skip to content

Commit bacfc1d

Browse files
committed
merge conflicts and validate v1.46 baseline changes
2 parents e690ae9 + 1587f90 commit bacfc1d

File tree

355 files changed

+3086
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

355 files changed

+3086
-367
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ importFrom(tools,file_ext)
269269
importFrom(tools,file_path_sans_ext)
270270
importFrom(utils,browseURL)
271271
importFrom(utils,data)
272+
importFrom(utils,file.edit)
272273
importFrom(utils,getFromNamespace)
273274
importFrom(utils,modifyList)
274275
importFrom(utils,packageVersion)

NEWS.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22

33
## Changes to plotly.js
44

5-
* This version of the R package upgrades the version of the underlying plotly.js library from v1.42.3 to v1.46.0. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes, but here is summary most pertainent ones for the R package:
5+
* This version of the R package upgrades the version of the underlying plotly.js library from v1.42.3 to v1.46.1. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes, but here is summary most pertainent ones for the R package:
66
* New trace types: `sunburst`, `waterfall`, `isosurface`.
77
* New `hovertemplate` attribute allows for finer-tuned control over tooltip text. See [here](https://plotly-r.com/controlling-tooltips.html#fig:tooltip-format-heatmap) for an example.
88
* Providing a string to `title` is now deprecated (but still works). Instead, use `title = list(text = "title")`. This change was made to support a new title placement API (e.g., `title = list(text = "title", xanchor = "left")`). Note that these changes are relevant for `layout.title` as well as `layout.xaxis.title`/`layout.yaxis.title`/etc.
99

10-
## NEW FEATURES
10+
## NEW FEATURES & IMPROVEMENTS
1111

12-
* The `orca_serve()` function was added for efficient exporting of many plotly graphs. For examples, see `help(orca_serve)`.
13-
* The `orca()` function gains new arguments `more_args` and `...` for finer control over the underlying system commands.
14-
* Improvements related to accessing plotly.js events in shiny:
15-
* The `event` argument of the `event_data()` function now supports the following events: `plotly_selecting`, `plotly_brushed`, `plotly_brushing`, `plotly_restyle`, `plotly_legendclick`, `plotly_legenddoubleclick`, `plotly_clickannotation`, `plotly_afterplot`, `plotly_doubleclick`, `plotly_deselect`, `plotly_unhover`. For examples, see `plotly_example("shiny", "event_data")`, `plotly_example("shiny", "event_data_legends")`, and `plotly_example("shiny", "event_data_annotation")`,
12+
* Several new features and improvements related to accessing plotly.js events in shiny (learn more about them in this RStudio [webinar](https://resources.rstudio.com/webinars/accessing-and-responding-to-plotly-events-in-shiny-carson-sievert)):
13+
* The `event` argument of the `event_data()` function now supports the following events: `plotly_selecting`, `plotly_brushed`, `plotly_brushing`, `plotly_restyle`, `plotly_legendclick`, `plotly_legenddoubleclick`, `plotly_clickannotation`, `plotly_afterplot`, `plotly_doubleclick`, `plotly_deselect`, `plotly_unhover`. For examples, see `plotly_example("shiny", "event_data")`, `plotly_example("shiny", "event_data_legends")`, and `plotly_example("shiny", "event_data_annotation")`,
1614
* New `event_register()` and `event_unregister()` functions for declaring which events to transmit over the wire (i.e., from the browser to the shiny server). Events that are likely to have large overhead are not registered by default, so you'll need to register these: `plotly_selecting`, `plotly_unhover`, `plotly_restyle`, `plotly_legendclick`, and `plotly_legenddoubleclick`.
17-
* A new `priority` argument. By setting `priority='event'`, the `event` is treated like a true event: any reactive expression using the `event` becomes invalidated (regardless of whether the input values has changed). For an example, see `plotly_example("shiny", "event_priority")`.
18-
* The `method` argument of `plotlyProxyInvoke()` gains support for a `"reconfig"` method. This makes it possible to change just the configuration of a plot. For an example use, see `plotly_example("shiny", "event_data_annotation")`.
19-
20-
## IMPROVEMENTS
21-
22-
* The `orca()` function now supports conversion of much larger figures (#1322) and works without a mapbox api token (#1314).
23-
* The `style()` function now supports "partial updates" (i.e. modification of a particular property of an object, rather than the entire object). For example, notice how the first plot retains the original marker shape (a square): `p <- plot_ly(x = 1:10, y = 1:10, symbol = I(15)); subplot(style(p, marker.color = "red"), style(p, marker = list(color = "red")))` (#1342).
15+
* A new `priority` argument. By setting `priority='event'`, the `event` is treated like a true event: any reactive expression using the `event` becomes invalidated (regardless of whether the input values has changed). For an example, see `plotly_example("shiny", "event_priority")`.
16+
* The `event_data()` function now relays the (official plotly.js) `customdata` attribute in similar fashion to (unofficial) `key` attribute (#1423). Run `plotly_example("shiny", "event_data")` for an example.
17+
* `event_data("plotly_selected")` is no longer too eager to clear. That is, it is no longer set to `NULL` when clicking on a plot *after* triggering the "plotly_selected" event (#1121) (#1122).
18+
19+
* Several new features and improvements for exporting static graphs with the orca command-line utility:
20+
* The `orca()` function now supports conversion of much larger figures (#1322) and works without a mapbox api token (#1314).
21+
* The `orca_serve()` function was added for efficient exporting of many plotly graphs. For examples, see `help(orca_serve)`.
22+
* The `orca()` function gains new arguments `more_args` and `...` for finer control over the underlying system commands.
23+
2424
* **plotly** objects can now be serialized and unserialized in different environments (i.e., you can now use `saveRDS()` to save an object as an rds file and restore it on another machine with `readRDS()`). Note this object is *dynamically* linked to JavaScript libraries, so one should take care to use consistent versions of **plotly** when serializing and unserializing (#1376).
25-
* The `plotly_example()` will now attempt to open the source file(s) used to run the example. Set `edit = FALSE` to prevent the source file(s) from opening.
26-
* The `event_data()` function now relays the (official plotly.js) `customdata` attribute in similar fashion to (unofficial) `key` attribute (#1423).
25+
* The `style()` function now supports "partial updates" (i.e. modification of a particular property of an object, rather than the entire object). For example, notice how the first plot retains the original marker shape (a square): `p <- plot_ly(x = 1:10, y = 1:10, symbol = I(15)); subplot(style(p, marker.color = "red"), style(p, marker = list(color = "red")))` (#1342).
26+
* The `method` argument of `plotlyProxyInvoke()` gains support for a `"reconfig"` method. This makes it possible to modify just the configuration of a plot in a **shiny** app. For an example use, see `plotly_example("shiny", "event_data_annotation")`.
27+
* The `plotly_example()` function will now attempt to open the source file(s) used to run the example. Set `edit = FALSE` to prevent the source file(s) from opening.
2728
* An informative warning is now thrown if invalid argument names are supplied to `config()`.
2829

2930
## CHANGES
@@ -36,9 +37,9 @@
3637
* `subplot()` now works much better with annotations, images, and shapes:
3738
- When `xref`/`yref` references an x/y axis these references are bumped accordingly (#1181).
3839
- When `xref`/`yref` references paper coordinates, these coordinates are updated accordingly (#1332).
39-
* `event_data("plotly_selected")` is no longer too eager to clear. That is, it is no longer set to `NULL` when clicking on a plot *after* triggering the "plotly_selected" event (#1121) (#1122).
4040
* The colorscale generated via the `color` argument in `plot_ly()` now uses an evenly spaced grid of values instead of quantiles (#1308).
4141
* When using **shinytest** to test a **shiny** that contains **plotly** graph, false positive differences are no longer reported (rstudio/shinytest#174).
42+
* When the `size` argument maps to `marker.size`, it now converts to an array of appropriate length (#1479).
4243
* The `color` and `stroke` arguments now work as expected for trace types with `fillcolor` but no `fill` attribute (e.g. `box` traces) (#1292).
4344
* Information emitted by in `event_data()` for heatmaps with atomic vectors for `x`/`y`/`z` is now correct (#1141).
4445
* Fixed issue where **dplyr** groups caused a problem in the ordering of data arrays passed to `marker` objects (#1351).
@@ -47,6 +48,7 @@
4748
* Clearing a highlight event via crosstalk no longer deletes all the traces added since initial draw (#1436).
4849
* Recursive attribute validation is now only performed on recursive objects (#1315).
4950
* The `text` attribute is no longer collapsed to a string when `hoveron='fills+points'` (#1448).
51+
* `layout.[x-y]axis.domain` is no longer supplied a default when `layout.grid` is specified (#1427).
5052

5153
# 4.8.0
5254

R/ggplotly.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,18 @@ gg2list <- function(p, width = NULL, height = NULL,
236236
out
237237
}
238238

239+
# ggplot2 3.1.0.9000 introduced a Layer method named setup_layer()
240+
# currently, LayerSf is the only core-ggplot2 Layer that makes use
241+
# of it https://github.com/tidyverse/ggplot2/pull/2875
242+
data <- layer_data
243+
if (packageVersion("ggplot2") > "3.1.0") {
244+
data <- by_layer(function(l, d) l$setup_layer(d, plot))
245+
}
246+
239247
# Initialise panels, add extra data for margins & missing facetting
240248
# variables, and add on a PANEL variable to data
241249
layout <- ggfun("create_layout")(plot$facet, plot$coordinates)
242-
data <- layout$setup(layer_data, plot$data, plot$plot_env)
250+
data <- layout$setup(data, plot$data, plot$plot_env)
243251

244252
# save the domain of the group for display in tooltips
245253
groupDomains <- Map(function(x, y) {

R/imports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' @import ggplot2
22
#' @importFrom grDevices col2rgb extendrange dev.list dev.off rgb as.raster
33
#' @importFrom graphics layout
4-
#' @importFrom utils getFromNamespace modifyList data packageVersion browseURL str
4+
#' @importFrom utils getFromNamespace modifyList data packageVersion browseURL str file.edit
55
#' @importFrom stats setNames complete.cases quantile is.leaf
66
#' @importFrom tidyr unnest
77
#' @importFrom viridisLite viridis

R/layers2traces.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,12 @@ aes2plotly <- function(data, params, aes = "size") {
10001000
type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else ""
10011001
ggfun("default_aesthetics")(type)
10021002
} else {
1003-
ggfun(geom)$default_aes
1003+
geom_obj <- ggfun(geom)
1004+
# If the first class of `data` is a data.frame,
1005+
# ggfun() returns a function because ggplot2 now
1006+
# defines data.frame in it's namespace
1007+
# https://github.com/ropensci/plotly/pull/1481
1008+
if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL
10041009
}
10051010

10061011
vals <- uniq(data[[aes]]) %||% params[[aes]] %||% defaults[[aes]] %||% NA

R/plotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ typedArrayPolyfill <- function() {
444444
plotlyMainBundle <- function() {
445445
htmltools::htmlDependency(
446446
name = "plotly-main",
447-
version = "1.46.0",
447+
version = "1.46.1",
448448
package = "plotly",
449449
src = dependency_dir("plotlyjs"),
450450
script = "plotly-latest.min.js",

R/plotly_build.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
377377

378378
p <- verify_guides(p)
379379

380+
# verify colorscale attributes are in a sensible data structure
381+
p <- verify_colorscale(p)
382+
380383
# verify plot attributes are legal according to the plotly.js spec
381384
p <- verify_attr_names(p)
382385
# box up 'data_array' attributes where appropriate
@@ -808,11 +811,6 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
808811
colorObj[c("cmin", "cmax")] <- NULL
809812
colorObj[["showscale"]] <- default(TRUE)
810813
traces[[i]] <- modify_list(colorObj, traces[[i]])
811-
traces[[i]]$colorscale <- as_df(traces[[i]]$colorscale)
812-
# sigh, contour colorscale doesn't support alpha
813-
if (grepl("contour", traces[[i]][["type"]])) {
814-
traces[[i]]$colorscale[, 2] <- strip_alpha(traces[[i]]$colorscale[, 2])
815-
}
816814
traces[[i]] <- structure(traces[[i]], class = c("plotly_colorbar", "zcolor"))
817815
next
818816
}
@@ -856,8 +854,6 @@ map_color <- function(traces, stroke = FALSE, title = "", colorway, na.color = "
856854
traces[[i]] <- modify_list(list(fillcolor = col), traces[[i]])
857855
}
858856

859-
# make sure the colorscale is going to convert to JSON nicely
860-
traces[[i]]$marker$colorscale <- as_df(traces[[i]]$marker$colorscale)
861857
}
862858
}
863859

R/shiny.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ prepareWidget <- function(x) {
6565
}
6666

6767
register_plot_events <- function(p) {
68-
session <- getDefaultReactiveDomain()
68+
session <- shiny::getDefaultReactiveDomain()
6969
eventIDs <- paste(p$x$shinyEvents, p$x$source, sep = "-")
7070
session$userData$plotlyShinyEventIDs <- unique(c(
7171
session$userData$plotlyShinyEventIDs,
@@ -153,7 +153,13 @@ event_data <- function(
153153
parseJSONVal(session$rootScope()$input[[eventID]])
154154
}
155155

156-
priority <- match.arg(priority)
156+
# events that don't emit any data should _always_ be treated with event priority
157+
priority <- if (event %in% c("plotly_doubleclick", "plotly_deselect", "plotly_afterplot")) {
158+
"event"
159+
} else {
160+
match.arg(priority)
161+
}
162+
157163
if (priority == "event") {
158164
# Shiny.setInputValue() is always called with event priority
159165
# so simply return the parse input value
@@ -181,6 +187,7 @@ event_data <- function(
181187
#' Register a shiny input value
182188
#'
183189
#' @inheritParams event_data
190+
#' @param p a plotly object.
184191
#' @seealso [event_data]
185192
#' @export
186193
#' @author Carson Sievert
@@ -192,6 +199,7 @@ event_register <- function(p, event = NULL) {
192199
#' Un-register a shiny input value
193200
#'
194201
#' @inheritParams event_data
202+
#' @param p a plotly object.
195203
#' @seealso [event_data]
196204
#' @export
197205
#' @author Carson Sievert

R/utils.R

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ colorway <- function(p = NULL) {
131131
# TODO: make this more unique?
132132
crosstalk_key <- function() ".crossTalkKey"
133133

134-
# modifyList turns elements that are data.frames into lists
135-
# which changes the behavior of toJSON
136-
as_df <- function(x) {
137-
if (is.null(x) || is.matrix(x)) return(x)
138-
if (is.list(x) && !is.data.frame(x)) {
139-
setNames(as.data.frame(x), NULL)
140-
}
141-
}
142-
143134
# arrange data if the vars exist, don't throw error if they don't
144135
arrange_safe <- function(data, vars) {
145136
vars <- vars[vars %in% names(data)]
@@ -349,7 +340,7 @@ supply_defaults <- function(p) {
349340
p$x$layout[[p$x$layout$mapType]] <- modify_list(
350341
list(domain = geoDomain), p$x$layout[[p$x$layout$mapType]]
351342
)
352-
} else {
343+
} else if (!length(p$x$layout[["grid"]])) {
353344
types <- vapply(p$x$data, function(tr) tr[["type"]] %||% "scatter", character(1))
354345
axes <- unlist(lapply(types, function(x) {
355346
grep("^[a-z]axis$", names(Schema$traces[[x]]$attributes), value = TRUE) %||% NULL
@@ -503,12 +494,22 @@ verify_attr <- function(proposed, schema) {
503494
proposed$name <- uniq(proposed$name)
504495
}
505496

506-
# if marker.sizemode='area', make sure marker.size is boxed up
507-
# (otherwise, when marker.size is a constant, it always sets the diameter!)
497+
# if marker.size was populated via `size` arg (i.e., internal map_size()),
498+
# then it should _always_ be an array
499+
# of appropriate length...
500+
# (when marker.size is a constant, it always sets the diameter!)
508501
# https://codepen.io/cpsievert/pen/zazXgw
509502
# https://github.com/plotly/plotly.js/issues/2735
510-
if ("area" %in% proposed$marker$sizemode) {
511-
proposed$marker[["size"]] <- i(proposed$marker[["size"]])
503+
if (is.default(proposed$marker$size)) {
504+
s <- proposed$marker[["size"]]
505+
if (length(s) == 1) {
506+
# marker.size could be of length 1, but we may have multiple
507+
# markers -- in that case, if marker.size is an array
508+
# of length 1 will result in just one marker
509+
# https://codepen.io/cpsievert/pen/aMmOza
510+
n <- length(proposed[["x"]] %||% proposed[["y"]] %||% proposed[["lat"]] %||% proposed[["lon"]])
511+
proposed$marker[["size"]] <- default(i(rep(s, n)))
512+
}
512513
}
513514

514515
# do the same for "sub-attributes"
@@ -658,6 +659,51 @@ verify_mode <- function(p) {
658659
p
659660
}
660661

662+
663+
verify_colorscale <- function(p) {
664+
p$x$data <- lapply(p$x$data, function(trace) {
665+
trace$colorscale <- colorscale_json(trace$colorscale)
666+
trace$marker$colorscale <- colorscale_json(trace$marker$colorscale)
667+
trace
668+
})
669+
p
670+
}
671+
672+
# Coerce `x` into a data structure that can map to a colorscale attribute.
673+
# Note that colorscales can either be the name of a scale (e.g., 'Rainbow') or
674+
# a 2D array (e.g., [[0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']])
675+
colorscale_json <- function(x) {
676+
if (!length(x)) return(x)
677+
if (is.character(x)) return(x)
678+
if (is.matrix(x)) {
679+
if (ncol(x) != 2) stop("A colorscale matrix requires two columns")
680+
x <- as.data.frame(x)
681+
x[, 1] <- as.numeric(x[, 1])
682+
}
683+
# ensure a list like this: list(list(0, 0.5, 1), list("red", "white", "blue"))
684+
# converts to the correct dimensions: [[0, 'red'], [0.5, 'white'], [1, 'blue']]
685+
if (is.list(x) && length(x) == 2) {
686+
n1 <- length(x[[1]])
687+
n2 <- length(x[[2]])
688+
if (n1 != n2 || n1 == 0 || n2 == 0) {
689+
warning("A colorscale list must of elements of the same (non-zero) length")
690+
} else if (!is.data.frame(x) && can_be_numeric(x[[1]])) {
691+
x <- data.frame(
692+
val = as.numeric(x[[1]]),
693+
col = as.character(x[[2]]),
694+
stringsAsFactors = FALSE
695+
)
696+
x <- setNames(x, NULL)
697+
}
698+
}
699+
x
700+
}
701+
702+
can_be_numeric <- function(x) {
703+
xnum <- suppressWarnings(as.numeric(x))
704+
sum(is.na(x)) == sum(is.na(xnum))
705+
}
706+
661707
# if an object (e.g. trace.marker) contains a non-default attribute, it has been user-specified
662708
user_specified <- function(obj = NULL) {
663709
if (!length(obj)) return(FALSE)

inst/docker/Dockerfile.vtest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ MAINTAINER Carson Sievert "[email protected]"
99

1010
# Don't print "debconf: unable to initialize frontend: Dialog" messages
1111
ARG DEBIAN_FRONTED=noninteractive
12+
ARG CACHEBUST=1
1213

1314
# Need this to add R repo
1415
RUN apt-get update && apt-get install -y software-properties-common
1516

1617
# Add R apt repository
17-
RUN add-apt-repository "deb http://cran.r-project.org/bin/linux/ubuntu $(lsb_release -cs)/"
18+
RUN add-apt-repository "deb http://cran.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran35/"
1819
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0x51716619e084dab9
1920

2021
# Install basic stuff and R

0 commit comments

Comments
 (0)