Skip to content

Commit c4d5d0c

Browse files
committed
Merge branch 'master' into scattergl
2 parents 5c7cdc9 + 3e9edb9 commit c4d5d0c

Some content is hidden

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

61 files changed

+1855
-594
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
CONDUCT.md
66
CONTRIBUTING.md
77
build_site.R
8+
travis_debug.R
89
todo.R
910
.github/
1011
inst/examples/rmd/*.html

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ inst/examples/*/rsconnect/*
1414
Untitled*
1515
rsconnect/
1616
revdep/
17+
travis_debug.R

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dist: trusty
66
r:
77
- oldrel
88
- release
9-
# - devel
9+
- devel
1010

1111
env:
1212
global:
@@ -15,6 +15,8 @@ env:
1515
- secure: "WsvmMHN4YVhnk0bLRE04APcLbs5s4vWKSHjEdU0bPXd0xdMTzZeP5D7pxyF1983C+P5LpSnGHv4dgwLMBkNzxJwBR7/Ta7lfO1akYILWwxib+1DVbCqUH5Z4Ba1FSCQptIrLNGR3P7+0Lem4hEhqKdPKltFnxhnXO0Y+MeG71IQ="
1616
# GITHUB_PAT (for pushing to plotly-test-table)
1717
- secure: "Ar5FRxsMJHxb8CQmmsoFx5Tm6ncFvF3LHtAMtfcOE2e9JAbXQ471PGzOMM7yudGa2vVuQJBpB6bWktuE30J68MQxgRmxeaJYmOp+ePqyW80y/zEa2P3R4//eb9Rif2lmsmaqz7HtVfX4xr3YX4N+ZjfyI8TFt5Phue18tXeMoJw="
18+
# MAPBOX_TOKEN (for testing `plot_mapbox()`)
19+
- secure: "QPBEqtLRdwb4ablJORzD0JdCT9ESe3nNdIehM1oxfcNKfpSdf2OFxH3TkeYY1nMpv0mLxiMNTy6xcj9Yk5MaaBCIA0P7q6OdZv9ruzQD1j3g84gP45KwBilbPGjb+/EvOS0fM25vR/pAmA8IyoUfPC2J8HwiNnW8DYdt/hJOJ9A="
1820

1921
# installing Rserve from source requires non-standard R build (--enable-R-shlib)
2022
r_binary_packages:

DESCRIPTION

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Imports:
4040
dplyr,
4141
tibble,
4242
lazyeval (>= 0.2.0),
43+
rlang,
4344
crosstalk,
4445
purrr,
4546
data.table
@@ -62,11 +63,14 @@ Suggests:
6263
listviewer,
6364
dendextend,
6465
sf,
66+
maptools,
67+
rgeos,
6568
RSelenium,
6669
png,
6770
IRdisplay
6871
Remotes:
6972
tidyverse/ggplot2
7073
LazyData: true
71-
RoxygenNote: 6.0.1
74+
RoxygenNote: 6.0.1.9000
75+
Encoding: UTF-8
7276
Roxygen: list(markdown = TRUE)

NAMESPACE

+3-11
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,10 @@ S3method(print,api)
3939
S3method(print,api_grid)
4040
S3method(print,api_grid_local)
4141
S3method(print,api_plot)
42+
S3method(print,plotly_data)
4243
S3method(rename_,plotly)
4344
S3method(select_,plotly)
4445
S3method(slice_,plotly)
45-
S3method(st_as_plotly,CIRCULARSTRING)
46-
S3method(st_as_plotly,COMPOUNDCURVE)
47-
S3method(st_as_plotly,CURVEPOLYGON)
48-
S3method(st_as_plotly,GEOMETRYCOLLECTION)
49-
S3method(st_as_plotly,LINESTRING)
50-
S3method(st_as_plotly,MULTILINESTRING)
51-
S3method(st_as_plotly,MULTIPOINT)
52-
S3method(st_as_plotly,MULTIPOLYGON)
53-
S3method(st_as_plotly,MULTISURFACE)
54-
S3method(st_as_plotly,POINT)
55-
S3method(st_as_plotly,POLYGON)
5646
S3method(summarise_,plotly)
5747
S3method(to_basic,GeomAbline)
5848
S3method(to_basic,GeomAnnotationMap)
@@ -112,6 +102,7 @@ export(add_polygons)
112102
export(add_ribbons)
113103
export(add_scattergeo)
114104
export(add_segments)
105+
export(add_sf)
115106
export(add_surface)
116107
export(add_text)
117108
export(add_trace)
@@ -257,6 +248,7 @@ importFrom(lazyeval,is_formula)
257248
importFrom(lazyeval,is_lang)
258249
importFrom(magrittr,"%>%")
259250
importFrom(purrr,transpose)
251+
importFrom(rlang,eval_tidy)
260252
importFrom(stats,complete.cases)
261253
importFrom(stats,is.leaf)
262254
importFrom(stats,quantile)

NEWS.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
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).
6-
* 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.
5+
* Upgraded to plotly.js v1.36.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).
6+
* 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")`).
8+
* 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.
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).
911

1012
## CHANGES
1113

14+
* 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"))`.
15+
* 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+
* `layout.showlegend` now defaults to `TRUE` for a *single* pie trace. This is a more sensible default and matches pure plotly.js behavior.
1218
* The `elementId` field is no longer populated, which fixes the "Ignoring explicitly provided widget ID" warning in shiny applications (see #985).
1319

1420
## BUG FIXES

R/add.R

+55
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,61 @@ add_polygons <- function(p, x = NULL, y = NULL, ...,
217217
}
218218

219219

220+
221+
#' @inheritParams add_trace
222+
#' @rdname add_trace
223+
#' @export
224+
#' @examples
225+
#'
226+
#' if (requireNamespace("sf", quietly = TRUE)) {
227+
#' nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
228+
#' plot_ly() %>% add_sf(data = nc)
229+
#' }
230+
add_sf <- function(p, ..., x = ~x, y = ~y, data = NULL, inherit = TRUE) {
231+
try_library("sf", "add_sf")
232+
dat <- plotly_data(add_data(p, data))
233+
if (!is_sf(dat)) {
234+
stop(
235+
"The `data` for an `add_sf()` layer must be an sf object, ",
236+
"not an object of class: ", class(dat)[1],
237+
call. = FALSE
238+
)
239+
}
240+
if (is_mapbox(p) || is_geo(p)) dat <- st_cast_crs(dat)
241+
bbox <- sf::st_bbox(dat)
242+
set <- attr(dat, "set")
243+
244+
d <- to_basic.GeomSf(dat)
245+
246+
# to_basic() returns either a single data frame or a list of data frames
247+
# (each data frame should be a a collection of the same feature type)
248+
d <- if (is.data.frame(d)) list(d)
249+
250+
# inherit attributes from the "first layer" (except the plotly_eval class)
251+
attrz <- if (inherit) modify_list(unclass(p$x$attrs[[1]]), list(...)) else list(...)
252+
253+
for (i in seq_along(d)) {
254+
# sensible mode/style defaults based on the feature type (e.g. polygon, path, point)
255+
attrs <- modify_list(sf_default_attrs(d[[i]]), attrz)
256+
# scatter3d doesn't currently support fill
257+
if ("z" %in% names(attrs)) attrs$fill <- NULL
258+
args <- list(
259+
p = p,
260+
class = "plotly_sf",
261+
x = x,
262+
y = y,
263+
`_bbox` = bbox,
264+
set = set,
265+
data = if ("group" %in% names(d[[i]])) group_by_(d[[i]], "group", add = TRUE) else d[[i]],
266+
inherit = inherit
267+
)
268+
p <- do.call(add_trace_classed, c(args, attrs))
269+
}
270+
271+
p
272+
}
273+
274+
220275
#' @inheritParams add_trace
221276
#' @rdname add_trace
222277
#' @export

R/coord.R

-66
This file was deleted.

R/data.R

+9
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@
2121
#' @format A data frame with three variables: `r`, `t`,
2222
#' `nms`.
2323
"hobbs"
24+
25+
26+
#' Minnesotan Indian Reservation Lands
27+
#'
28+
#' @references \url{https://www.dot.state.mn.us/maps/gdma/gis-data.html}
29+
#'
30+
#' @format An sf data frame with 13 features and 5 fields
31+
#'
32+
"res_mn"

R/dev.R

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
#' sent to plotly.js.
55
#'
66
#' @param p a plotly or ggplot object.
7-
#' @param jsonedit use `listviewer::jsonedit` to view the JSON?
8-
#' @param ... other options passed onto `listviewer::jsonedit`
7+
#' @param jsonedit use [listviewer::jsonedit] to view the JSON?
8+
#' @param pretty adds indentation whitespace to JSON output. Can be TRUE/FALSE
9+
#' or a number specifying the number of spaces to indent. See [jsonlite::prettify].
10+
#' @param ... other options passed onto [listviewer::jsonedit]
911
#' @export
1012
#' @examples
1113
#'
1214
#' plotly_json(plot_ly())
1315
#' plotly_json(plot_ly(), FALSE)
1416

15-
plotly_json <- function(p = last_plot(), jsonedit = interactive(), ...) {
16-
plotlyJSON <- to_JSON(plotly_build(p)$x, pretty = TRUE)
17+
plotly_json <- function(p = last_plot(), jsonedit = interactive(), pretty = TRUE, ...) {
18+
plotlyJSON <- to_JSON(plotly_build(p)$x, pretty = pretty)
1719
if (jsonedit) {
1820
try_library("listviewer", "plotly_json")
1921
listviewer::jsonedit(plotlyJSON, mode = "form", ...)

R/ggplotly.R

+5-6
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,9 @@ gg2list <- function(p, width = NULL, height = NULL,
261261

262262
# save the domain of the group for display in tooltips
263263
groupDomains <- Map(function(x, y) {
264-
tryCatch(
265-
eval(y$mapping[["group"]] %||% plot$mapping[["group"]], x),
266-
error = function(e) NULL
267-
)
264+
aes_g <- y$mapping[["group"]] %||% plot$mapping[["group"]]
265+
eval_ <- if (is_dev_ggplot2()) rlang::eval_tidy else base::eval
266+
tryNULL(eval_(aes_g, x))
268267
}, data, layers)
269268

270269
# for simple (StatIdentity) geoms, add crosstalk key to aes mapping
@@ -976,8 +975,8 @@ gg2list <- function(p, width = NULL, height = NULL,
976975
for (i in seq_along(traces)) {
977976
tr <- traces[[i]]
978977
# flipping logic for bar positioning is in geom2trace.GeomBar
979-
if (tr$type != "bar") traces[[i]][c("x", "y")] <- tr[c("y", "x")]
980-
if (tr$type %in% "box") {
978+
if (!identical(tr$type, "bar")) traces[[i]][c("x", "y")] <- tr[c("y", "x")]
979+
if (identical(tr$type, "box")) {
981980
traces[[i]]$orientation <- "h"
982981
traces[[i]]$hoverinfo <- "x"
983982
}

R/helpers.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ colorbar_built <- function(p, ..., limits = NULL, which = 1) {
6363
# since the colorscale is in a different trace, retrain all traces
6464
p$x$data <- lapply(p$x$data, function(x) {
6565
col <- x$marker[["color"]]
66-
x$marker[["color"]][col < limits[1] | limits[2] < col] <- NA
67-
x$marker[["cmin"]] <- limits[1]
68-
x$marker[["cmax"]] <- limits[2]
66+
x$marker[["color"]][col < limits[1] | limits[2] < col] <- default(NA)
67+
x$marker[["cmin"]] <- default(limits[1])
68+
x$marker[["cmax"]] <- default(limits[2])
6969
x
7070
})
7171
}
@@ -110,10 +110,10 @@ hide_colorbar <- function(p) {
110110
for (i in seq_along(p$x$data)) {
111111
trace <- p$x$data[[i]]
112112
if (has_attr(trace$type, "showscale")) {
113-
p$x$data[[i]]$showscale <- FALSE
113+
p$x$data[[i]]$showscale <- default(FALSE)
114114
}
115115
if (has_attr(trace$type, "marker")) {
116-
p$x$data[[i]]$marker$showscale <- FALSE
116+
p$x$data[[i]]$marker$showscale <- default(FALSE)
117117
}
118118
}
119119
p
@@ -144,7 +144,7 @@ hide_legend <- function(p) {
144144
#' @examples
145145
#'
146146
#' # currently no bargl trace type
147-
#' toWebGL(qplot(1:10))
147+
#' toWebGL(ggplot() + geom_bar(aes(1:10)))
148148
#' toWebGL(qplot(1:10, 1:10))
149149
#'
150150
toWebGL <- function(p) {

R/imports.R

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#' @importFrom purrr transpose
1515
#' @importFrom tools file_ext file_path_sans_ext
1616
#' @importFrom data.table as.data.table setorderv
17+
#' @importFrom rlang eval_tidy
1718
NULL
1819

1920

0 commit comments

Comments
 (0)