Skip to content

Commit fbc5114

Browse files
committed
merge conflicts
2 parents d365372 + c79ba2c commit fbc5114

Some content is hidden

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

105 files changed

+1043
-130
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Imports:
4343
rlang,
4444
crosstalk,
4545
purrr,
46-
data.table
46+
data.table,
47+
promises
4748
Suggests:
4849
MASS,
4950
maps,
@@ -52,7 +53,7 @@ Suggests:
5253
testthat,
5354
knitr,
5455
devtools,
55-
shiny (>= 0.14),
56+
shiny (>= 1.1.0),
5657
curl,
5758
rmarkdown,
5859
Rserve,
@@ -65,9 +66,9 @@ Suggests:
6566
sf,
6667
maptools,
6768
rgeos,
68-
RSelenium,
6969
png,
70-
IRdisplay
70+
IRdisplay,
71+
processx
7172
LazyData: true
7273
RoxygenNote: 6.0.1.9000
7374
Encoding: UTF-8

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export(layout)
149149
export(mutate)
150150
export(mutate_)
151151
export(offline)
152+
export(orca)
153+
export(partial_bundle)
152154
export(plot_dendro)
153155
export(plot_geo)
154156
export(plot_ly)

NEWS.md

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,61 @@
22

33
## NEW FEATURES & IMPROVEMENTS
44

5-
* Upgraded to plotly.js v1.37.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).
5+
### plotly.js and `plot_ly()` specific improvements
6+
7+
* Upgraded to plotly.js v1.38.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 six new trace types (`cone`, `scatterpolar`, `scatterpolargl`, `splom`, `table`, & `violin`)! See [here](https://github.com/plotly/plotly.js/releases) for a complete list of plotly.js-specific improvements.
68
* 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.
7-
* 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")`).
9+
* Better control over the stroke (i.e., outline) appearance of various filled graphical marks via the new "special arguments" (`stroke`, `strokes`, `alpha_stroke`, `span`, and `spans`). 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")`).
10+
11+
### `ggplotly()` specific improvements
12+
13+
* `ggplotly()` now supports conversion of **ggplot2**'s `geom_sf()`.
814
* 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")`.
15+
16+
### Other improvements relevant for all **plotly** objects
17+
918
* 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.
10-
* 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)
11-
* 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).
19+
* The `highlight()` function gains a `debounce` argument for throttling the rate at which `on` events may be fired. This is mainly useful for improving user experience when `highlight(on = "plotly_hover")` and mousing over relevant markers at a rapid rate (#1277)
20+
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.
21+
* The `config()` function gains a `locale` argument for easily changing localization defaults (#1270). This makes it possible localize date axes, and in some cases, modebar buttons (#1270).
22+
* 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 (#1116).
23+
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (#1205).
24+
* Support for async rendering of inside **shiny** apps using the [promises](https://rstudio.github.io/promises/) package (#1209).
1225

1326
## CHANGES
1427

28+
### `plot_ly()` specific changes
29+
30+
* The `name` attribute is now a "special `plot_ly()` argument" and behaves similar to `split` (it ensures a different trace for every unique value supplied). Although this leads to a breaking change (`name` was previously appended to an automatically generated trace name), it leads to a more flexible and transparent API. Those that wish to have the old behavior back should provide relevant mappings to the `name` attributes (e.g. `plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(vs), name = "a")` should become `plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~factor(vs), name = ~paste(vs, "\na"))`)
1531
* 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"))`.
1632
* 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")`).
1733
* 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))`).
1834
* `layout.showlegend` now defaults to `TRUE` for a *single* pie trace. This is a more sensible default and matches pure plotly.js behavior.
19-
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (see #985).
35+
36+
### Other changes relevant for all **plotly** objects
37+
38+
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (#985).
2039

2140
## BUG FIXES
2241

23-
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (see #1218).
24-
* Fixed algorithm for coercing the proposed layout to the plot schema (see #1156).
42+
### `ggplotly()` specific fixes
43+
2544
* 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).
45+
* In RStudio, `ggplotly()` was ignoring a specified `height`/`width` (#1190).
46+
* `ggplotly()` now uses fixed heights for facet strips meaning that their height is still correct after a window resize (#1265).
47+
48+
### `plot_ly()` specific fixes
49+
50+
* The `limits` argument of `colorbar()` wasn't being applied to `line.color`/`line.cmin`/`line.cmax` (#1236).
51+
* The `legendgroup` can now properly map data values (#1148).
52+
53+
### Other fixes relevant for all **plotly** objects
54+
55+
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (#1218).
56+
* Resizing behavior, after updating `height`/`width` via **shiny** reactive values, is now correct (#1068).
57+
* Fixed algorithm for coercing the proposed layout to the plot schema (#1156).
58+
* `add_*()` no longer inherits `crosstalk::SharedData` key information when `inherit = FALSE` (#1242).
59+
2960

3061
# 4.7.1
3162

R/export.R

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#' Export a plotly graph to a static file
22
#'
3+
#' This function is in the process of being deprecated (use [orca] instead).
4+
#'
35
#' @details For SVG plots, a screenshot is taken via `webshot::webshot()`.
46
#' Since `phantomjs` (and hence `webshot`) does not support WebGL,
57
#' the RSelenium package is used for exporting WebGL plots.
@@ -9,43 +11,16 @@
911
#' Valid extensions include 'jpeg' | 'png' | 'webp' | 'svg' | 'pdf'
1012
#' @param selenium used only when `p` is a WebGL plot or the output
1113
#' format is 'webp' or 'svg'. Should be an object of class "rsClientServer"
12-
#' returned by `RSelenium::rsDriver` (see examples).
14+
#' returned by `RSelenium::rsDriver`.
1315
#' @param ... if `p` is non-WebGL and the output file format is
1416
#' jpeg/png/pdf arguments are passed along to `webshot::webshot()`.
1517
#' Otherwise, they are ignored.
1618
#' @export
1719
#' @author Carson Sievert
18-
#' @examples
19-
#' # The webshot package handles non-WebGL conversion to jpeg/png/pdf
20-
#' \dontrun{
21-
#' export(plot_ly(economics, x = ~date, y = ~pce))
22-
#' export(plot_ly(economics, x = ~date, y = ~pce), "plot.pdf")
23-
#'
24-
#' # svg/webp output or WebGL conversion can be done via RSelenium
25-
#' if (requireNamespace("RSelenium")) {
26-
#' rD <- RSelenium::rsDriver(browser = "chrome")
27-
#' export(
28-
#' plot_ly(economics, x = ~date, y = ~pce), "plot.svg", rD
29-
#' )
30-
#' export(
31-
#' plot_ly(economics, x = ~date, y = ~pce, z = ~pop), "yay.svg", rD
32-
#' )
33-
#' }
34-
#'
35-
#' # If you can't get a selenium server running, another option is to
36-
#' # use Plotly.downloadImage() via htmlwidgets::onRender()...
37-
#' # Downloading images won't work inside RStudio, but you can set the viewer
38-
#' # option to NULL to prompt your default web browser
39-
#' options(viewer = NULL)
40-
#' plot_ly(economics, x = ~date, y = ~pce, z = ~pop) %>%
41-
#' htmlwidgets::onRender(
42-
#' "function(el, x) {
43-
#' var gd = document.getElementById(el.id);
44-
#' Plotly.downloadImage(gd, {format: 'png', width: 600, height: 400, filename: 'plot'});
45-
#' }"
46-
#' )
47-
#'}
20+
#'
4821
export <- function(p = last_plot(), file = "plotly.png", selenium = NULL, ...) {
22+
.Deprecated("orca")
23+
4924
# infer the file type
5025
fileType <- tolower(tools::file_ext(file))
5126
if (!fileType %in% c('jpeg', 'png', 'webp', 'svg', 'pdf')) {

R/ggplotly.R

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ gg2list <- function(p, width = NULL, height = NULL,
193193
}
194194
# if a device (or RStudio) is already open, use the device size as default size
195195
if (!is.null(grDevices::dev.list()) || is_rstudio()) {
196-
width <- width %||% grDevices::dev.size("px")[1]
197-
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])
198198
}
199199
# open the device and make sure it closes on exit
200200
dev_fun(file = tempfile(), width = width %||% 640, height = height %||% 480)
@@ -1014,8 +1014,8 @@ gg2list <- function(p, width = NULL, height = NULL,
10141014
# If a trace isn't named, it shouldn't have additional hoverinfo
10151015
traces <- lapply(compact(traces), function(x) { x$name <- x$name %||% ""; x })
10161016

1017-
gglayout$width <- width
1018-
gglayout$height <- height
1017+
gglayout$width <- width %|D|% NULL
1018+
gglayout$height <- height %|D|% NULL
10191019
gglayout$barmode <- gglayout$barmode %||% "relative"
10201020

10211021
l <- list(
@@ -1221,21 +1221,31 @@ uniq <- function(x) {
12211221
make_strip_rect <- function(xdom, ydom, theme, side = "top") {
12221222
rekt <- rect2shape(theme[["strip.background"]])
12231223
stripTextX <- theme[["strip.text.x"]] %||% theme[["strip.text"]]
1224-
xTextSize <- unitConvert(stripTextX$size, "npc", "width")
1224+
topSize <-
1225+
mm2pixels(grid::convertHeight(stripTextX$margin[1], "mm")) +
1226+
mm2pixels(grid::convertHeight(stripTextX$margin[3], "mm")) +
1227+
mm2pixels(grid::convertHeight(grid::unit(stripTextX$size, units = "points"), "mm"))
12251228
stripTextY <- theme[["strip.text.y"]] %||% theme[["strip.text"]]
1226-
yTextSize <- unitConvert(stripTextY$size, "npc", "height")
1229+
rightSize <-
1230+
mm2pixels(grid::convertWidth(stripTextX$margin[2], "mm")) +
1231+
mm2pixels(grid::convertWidth(stripTextX$margin[4], "mm")) +
1232+
mm2pixels(grid::convertWidth(grid::unit(stripTextY$size, units = "points"), "mm"))
12271233
if ("right" %in% side) {
12281234
# x-padding should be accounted for in `layout.margin.r`
1229-
rekt$x0 <- xdom[2]
1230-
rekt$x1 <- xdom[2] + xTextSize
12311235
rekt$y0 <- ydom[1]
12321236
rekt$y1 <- ydom[2]
1237+
rekt$x0 <- 0
1238+
rekt$x1 <- rightSize
1239+
rekt$xanchor <- xdom[2]
1240+
rekt$xsizemode <- "pixel"
12331241
}
12341242
if ("top" %in% side) {
12351243
rekt$x0 <- xdom[1]
12361244
rekt$x1 <- xdom[2]
1237-
rekt$y0 <- ydom[2]
1238-
rekt$y1 <- ydom[2] + yTextSize
1245+
rekt$y0 <- 0
1246+
rekt$y1 <- topSize
1247+
rekt$yanchor <- ydom[2]
1248+
rekt$ysizemode <- "pixel"
12391249
}
12401250
list(rekt)
12411251
}

R/highlight.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#' @param opacityDim a number between 0 and 1 used to reduce the
4444
#' opacity of non-selected traces (by multiplying with the existing opacity).
4545
#' @param selected attributes of the selection, see [attrs_selected()].
46+
#' @param debounce amount of time to wait before firing an event (in milliseconds).
47+
#' The default of 0 means do not debounce at all.
48+
#' Debouncing is mainly useful when `on = "plotly_hover"` to avoid firing too many events
49+
#' when users clickly move the mouse over relevant graphical marks.
4650
#' @param ... currently not supported.
4751
#' @export
4852
#' @author Carson Sievert
@@ -80,7 +84,8 @@ highlight <- function(p, on = "plotly_click", off,
8084
dynamic = FALSE, color = NULL,
8185
selectize = FALSE, defaultValues = NULL,
8286
opacityDim = getOption("opacityDim", 0.2),
83-
selected = attrs_selected(), ...) {
87+
selected = attrs_selected(), debounce = 0,
88+
...) {
8489

8590
# currently ... is not-supported and will catch
8691
# some arguments we supported at one point
@@ -154,7 +159,8 @@ highlight <- function(p, on = "plotly_click", off,
154159
selectize = selectize,
155160
defaultValues = defaultValues,
156161
opacityDim = opacityDim,
157-
selected = selected
162+
selected = selected,
163+
debounce = debounce
158164
)
159165

160166
p

R/layers2traces.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ to_basic.GeomRect <- function(data, prestats_data, layout, params, p, ...) {
272272
#' @export
273273
to_basic.GeomSf <- function(data, prestats_data, layout, params, p, ...) {
274274

275-
data <- sf::st_as_sf(data)
275+
data[["geometry"]] <- sf::st_sfc(data[["geometry"]])
276+
data <- sf::st_as_sf(data, sf_column_name = "geometry")
276277
geom_type <- sf::st_geometry_type(data)
277278
# st_cast should "expand" a collection into multiple rows (one per feature)
278279
if ("GEOMETRYCOLLECTION" %in% geom_type) {

R/layout.R

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,42 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
9090
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js}
9191
#' @param collaborate include the collaborate mode bar button (unique to the R pkg)?
9292
#' @param cloud include the send data to cloud button?
93+
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info.
9394
#' @author Carson Sievert
9495
#' @export
9596
#' @examples
9697
#'
97-
#' config(plot_ly(), displaylogo = FALSE, collaborate = FALSE)
98+
#' today <- Sys.Date()
99+
#' x <- seq.Date(today, today + 360, by = "day")
100+
#' p <- plot_ly(x = x, y = rnorm(length(x))) %>%
101+
#' add_lines()
102+
#'
103+
#' # remove the plotly logo and collaborate button from modebar
104+
#' config(p, displaylogo = FALSE, collaborate = FALSE)
105+
#'
106+
#' # japanese
107+
#' config(p, locale = "ja")
108+
#' # german
109+
#' config(p, locale = "de")
110+
#' # swiss-german
111+
#' config(p, locale = "de-CH")
112+
#' # spanish
113+
#' config(p, locale = "es")
114+
#' # french
115+
#' config(p, locale = "fr")
116+
#' # chinese
117+
#' config(p, locale = "zh-CN")
98118
#'
99119

100-
config <- function(p, ..., collaborate = TRUE, cloud = FALSE) {
120+
config <- function(p, ..., collaborate = TRUE, cloud = FALSE, locale = NULL) {
121+
122+
if (!is.null(locale)) {
123+
p$dependencies <- c(
124+
p$dependencies,
125+
list(locale_dependency(locale))
126+
)
127+
p$x$config$locale <- locale
128+
}
101129

102130
p$x$config <- modify_list(p$x$config, list(...))
103131

0 commit comments

Comments
 (0)