Skip to content

Commit 80004a3

Browse files
committed
merge conflicts
2 parents cf2b91e + d6823a5 commit 80004a3

Some content is hidden

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

62 files changed

+1963
-599
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 3 additions & 11 deletions
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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
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.37.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")`).
68
* 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")`.
79
* 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()`.
8-
* 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.
10+
* 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.
911
* 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)
1012
* 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).
1113

1214
## CHANGES
1315

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

1622
## BUG FIXES
1723

1824
* Bug fix for linking views with crosstalk where the source of the selection is an aggregated trace (see #1218).
1925
* Fixed algorithm for coercing the proposed layout to the plot schema (see #1156).
2026
* grid conversions in `ggplotly()` weren't respected a specified `height`/`width` in RStudio (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)
2129

2230
# 4.7.1
2331

R/add.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ add_trace <- function(p, ...,
5757

5858
# "native" plotly arguments
5959
attrs <- list(...)
60+
attrs$inherit <- inherit
6061

6162
if (!is.null(attrs[["group"]])) {
6263
warning("The group argument has been deprecated. Use group_by() or split instead.")
@@ -217,6 +218,61 @@ add_polygons <- function(p, x = NULL, y = NULL, ...,
217218
}
218219

219220

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

R/coord.R

Lines changed: 0 additions & 66 deletions
This file was deleted.

R/data.R

Lines changed: 9 additions & 0 deletions
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

Lines changed: 6 additions & 4 deletions
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", ...)

0 commit comments

Comments
 (0)