Skip to content

Commit 51a8099

Browse files
committed
Merge branch 'master' into avoid_reduce
2 parents db622ad + e2c3b23 commit 51a8099

File tree

352 files changed

+933
-778
lines changed

Some content is hidden

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

352 files changed

+933
-778
lines changed

NEWS.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# 4.8.0.9000
22

3+
## Changes to plotly.js
4+
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:
6+
* New trace types: `sunburst`, `waterfall`, `isosurface`.
7+
* 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.
8+
* 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.
9+
310
## NEW FEATURES & IMPROVEMENTS
411

5-
* Upgraded to plotly.js v1.42.5.
612
* 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)):
713
* 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")`,
814
* 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`.
@@ -14,21 +20,27 @@
1420
* The `orca()` function now supports conversion of much larger figures (#1322) and works without a mapbox api token (#1314).
1521
* The `orca_serve()` function was added for efficient exporting of many plotly graphs. For examples, see `help(orca_serve)`.
1622
* The `orca()` function gains new arguments `more_args` and `...` for finer control over the underlying system commands.
17-
23+
24+
* `ggplotly()` now respects horizontal alignment of **ggplot2** titles (e.g., `ggplotly(qplot(1:10) + ggtitle("A title") + theme(plot.title = element_text(hjust = 1)))`).
1825
* **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).
1926
* 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).
2027
* 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")`.
2128
* 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.
29+
* An informative warning is now thrown if invalid argument names are supplied to `config()`.
2230

2331
## CHANGES
2432

25-
* The 'collaborate' button no longer appears in the modebar, and as a result, the `config()` function no longer has a `collaborate` argument.
33+
* If `stroke` is specified, `span` now defaults to `I(1)`. This results in a slightly narrower default span for some trace types (e.g., `box`, `contour`), but it also ensures the `stroke` is always visible when it's relevant (e.g. `plot_ly(x = 1:10, y = 1:10, stroke = I("black"))`), making for a more consistent overall default (#1507).
34+
* The 'collaborate' button no longer appears in the modebar, and is longer supported, so the `config()` function no longer has a `collaborate` argument.
35+
* The `cloud` argument is now deprecated and will be removed in a future version. Use `showSendToCloud` instead.
36+
* `ggplotly()` now translates title information to `layout.title.text` (instead of `layout.title`) and `layout.title.font` (instead of `layout.titlefont`)
2637

2738
## BUG FIXES
2839

2940
* `subplot()` now works much better with annotations, images, and shapes:
3041
- When `xref`/`yref` references an x/y axis these references are bumped accordingly (#1181).
3142
- When `xref`/`yref` references paper coordinates, these coordinates are updated accordingly (#1332).
43+
* `subplot()` now repositions shapes with fixed height/width (i.e., `xsizemode`/`ysizemode` of `"pixel"`) correctly (#1494).
3244
* The colorscale generated via the `color` argument in `plot_ly()` now uses an evenly spaced grid of values instead of quantiles (#1308).
3345
* When using **shinytest** to test a **shiny** that contains **plotly** graph, false positive differences are no longer reported (rstudio/shinytest#174).
3446
* When the `size` argument maps to `marker.size`, it now converts to an array of appropriate length (#1479).
@@ -41,6 +53,7 @@
4153
* Recursive attribute validation is now only performed on recursive objects (#1315).
4254
* The `text` attribute is no longer collapsed to a string when `hoveron='fills+points'` (#1448).
4355
* `layout.[x-y]axis.domain` is no longer supplied a default when `layout.grid` is specified (#1427).
56+
* When uploading charts to a plot.ly account via `api_create()`, layout attributes are no longer incorrectly src-ified, which was causing inconsistencies in local/remote rendering of `ggplotly()` charts (#1197).
4457

4558
# 4.8.0
4659

R/ggplotly.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,15 @@ gg2list <- function(p, width = NULL, height = NULL,
437437
)
438438
# main plot title
439439
if (nchar(plot$labels$title %||% "") > 0) {
440-
gglayout$title <- faced(plot$labels$title, theme$plot.title$face)
441-
gglayout$titlefont <- text2font(theme$plot.title)
442-
gglayout$margin$t <- gglayout$margin$t + gglayout$titlefont$size
440+
gglayout$title <- list(
441+
text = faced(plot$labels$title, theme$plot.title$face),
442+
font = text2font(theme$plot.title),
443+
# don't translate vjust to y since they since have very different meaning...
444+
# y is allowed to span the paper coordinate whereas vjust it local to it's grob
445+
x = theme$plot.title$hjust,
446+
xref = "paper"
447+
)
448+
gglayout$margin$t <- gglayout$margin$t + gglayout$title$font$size
443449
}
444450
# ensure there's enough space for the modebar (this is based on a height of 1em)
445451
# https://github.com/plotly/plotly.js/blob/dd1547/src/components/modebar/index.js#L171
@@ -695,8 +701,11 @@ gg2list <- function(p, width = NULL, height = NULL,
695701
gridwidth = unitConvert(panelGrid, "pixels", type),
696702
zeroline = FALSE,
697703
anchor = anchor,
698-
title = faced(axisTitleText, axisTitle$face),
699-
titlefont = text2font(axisTitle)
704+
# layout.axisid.title don't yet support alignment :(
705+
title = list(
706+
text = faced(axisTitleText, axisTitle$face),
707+
font = text2font(axisTitle)
708+
)
700709
)
701710

702711
# set scaleanchor/scaleratio if these are fixed coordinates

R/layout.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
8888
#' @param p a plotly object
8989
#' @param ... these arguments are documented at
9090
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js}
91-
#' @param cloud include the send data to cloud button?
91+
#' @param cloud deprecated. Use `showSendToCloud` instead.
92+
#' @param showSendToCloud include the send data to cloud button?
9293
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info.
9394
#' @param mathjax add [MathJax rendering support](https://github.com/plotly/plotly.js/tree/master/dist#to-support-mathjax).
9495
#' If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for
@@ -130,7 +131,7 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
130131
#' config(p, locale = "zh-CN")
131132
#'
132133

133-
config <- function(p, ..., cloud = FALSE, locale = NULL, mathjax = NULL) {
134+
config <- function(p, ..., cloud = FALSE, showSendToCloud = cloud, locale = NULL, mathjax = NULL) {
134135

135136
if (!is.null(locale)) {
136137
p$dependencies <- c(
@@ -158,7 +159,8 @@ config <- function(p, ..., cloud = FALSE, locale = NULL, mathjax = NULL) {
158159
args <- list(...)
159160
if ("collaborate" %in% names(args)) warning("The collaborate button is no longer supported")
160161
p$x$config <- modify_list(p$x$config, args)
161-
p$x$config$cloud <- cloud
162+
if (cloud) warning("The `cloud` argument is deprecated. Use `showSendToCloud` instead.")
163+
p$x$config$showSendToCloud <- showSendToCloud
162164

163165
p
164166
}

R/partial_bundles.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ verify_partial_bundle <- function(p) {
110110
# verify that this partial bundle actually supports this viz
111111
# (at this point, bundleType should never be 'auto' or 'main')
112112
missingTypes <- setdiff(types, bundleTraceMap[[bundleType]])
113+
113114
if (length(missingTypes)) {
114115
msg <- sprintf(
115116
"The '%s' bundle supports the following trace types: '%s'.\n\n This plotly visualization contains the following trace types: '%s'",
@@ -188,7 +189,8 @@ bundleTraceMap <- list(
188189
"scatter3d",
189190
"surface",
190191
"mesh3d",
191-
"cone"
192+
"cone",
193+
"isosurface"
192194
),
193195
gl2d = c(
194196
"scatter",
@@ -209,6 +211,7 @@ bundleTraceMap <- list(
209211
"pie",
210212
"histogram",
211213
"ohlc",
212-
"candlestick"
214+
"candlestick",
215+
"waterfall"
213216
)
214217
)

R/plotly.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,10 @@ typedArrayPolyfill <- function() {
441441
)
442442
}
443443

444-
# TODO: suggest a plotlyBundles package that has trace-level bundles
445-
# and bundle size at print time.
446444
plotlyMainBundle <- function() {
447445
htmltools::htmlDependency(
448446
name = "plotly-main",
449-
version = "1.42.5",
447+
version = "1.46.1",
450448
package = "plotly",
451449
src = dependency_dir("plotlyjs"),
452450
script = "plotly-latest.min.js",

R/plotly_build.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
136136
trace <- verify_type(trace)
137137
# verify orientation of boxes/bars
138138
trace <- verify_orientation(trace)
139+
# supply sensible defaults based on trace type
140+
trace <- coerce_attr_defaults(trace, p$x$layout)
141+
142+
139143

140144
# attach crosstalk info, if necessary
141145
if (crosstalk_key() %in% names(dat) && isTRUE(trace[["inherit"]] %||% TRUE)) {
@@ -1018,3 +1022,21 @@ has_fill <- function(trace) {
10181022
if (has_fillcolor && isTRUE(fill != "none")) return(TRUE)
10191023
FALSE
10201024
}
1025+
1026+
# ensure we've set a sensible trace defaults
1027+
# based on the trace type
1028+
coerce_attr_defaults <- function(trace, layout) {
1029+
# if user has specified stroke, make sure the span
1030+
# defaults to something greater than 0 (so they can see the stroke!)
1031+
if (length(trace[["stroke"]]) && !is.default(trace[["stroke"]])) {
1032+
trace$span <- trace[["span"]] %||% default(I(1))
1033+
}
1034+
if (trace[["type"]] %in% c("sunburst", "pie")) {
1035+
# As of v1.46.1, paper_bgcolor defaults to '#fff' which
1036+
# col2rgb() can't parse, but expands to '#ffffff'
1037+
# https://stackoverflow.com/a/2899224/1583084
1038+
bgcolor <- layout$paper_bgcolor %||% "#ffffff"
1039+
trace$stroke <- trace[["stroke"]] %||% default(I(bgcolor))
1040+
}
1041+
trace
1042+
}

R/shiny.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#' @param outputId output variable to read from
77
#' @param width,height Must be a valid CSS unit (like \code{"100\%"},
88
#' `"400px"`, `"auto"`) or a number, which will be coerced to a
9-
#' string and have `"px"` appended.
9+
#' string and have `"px"` appended. Note that, for height, using "auto"
10+
#' or "100%" generally will not work as expected, because of how
11+
#' height is computed with HTML/CSS.
1012
#' @param inline use an inline (`span()`) or block container
1113
#' (`div()`) for the output
1214
#' @param expr An expression that generates a plotly

R/subplots.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ reposition <- function(obj, domains) {
421421
o <- obj[[i]]
422422
xs <- if (identical(o$xref, "paper")) {
423423
if (is.numeric(o$sizex)) obj[[i]]$sizex <- o$sizex * abs(diff(xdom))
424-
c("x", "x0", "x1")
424+
if (identical(o$xsizemode, "pixel")) "xanchor" else c("x", "x0", "x1")
425425
}
426426
for (j in xs) {
427427
if (is.numeric(o[[j]])) {
@@ -430,7 +430,7 @@ reposition <- function(obj, domains) {
430430
}
431431
ys <- if (identical(o$yref, "paper")) {
432432
if (is.numeric(o$sizey)) obj[[i]]$sizey <- o$sizey * abs(diff(ydom))
433-
c("y", "y0", "y1")
433+
if (identical(o$ysizemode, "pixel")) "yanchor" else c("y", "y0", "y1")
434434
}
435435
for (j in ys) {
436436
if (is.numeric(o[[j]])) {

R/sysdata.rda

19.9 KB
Binary file not shown.

R/utils.R

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ getLevels <- function(x) {
102102
tryNULL <- function(expr) tryCatch(expr, error = function(e) NULL)
103103

104104
# Don't attempt to do "tidy" data training on these trace types
105+
# Note that non-tidy traces expect/anticipate data_array's of varying lengths
105106
is_tidy <- function(trace) {
106107
type <- trace[["type"]] %||% "scatter"
107108
!type %in% c(
108-
"mesh3d", "heatmap", "histogram2d",
109+
"mesh3d", "heatmap", "histogram2d", "isosurface",
109110
"histogram2dcontour", "contour", "surface"
110111
)
111112
}
@@ -416,6 +417,11 @@ verify_attr_names <- function(p) {
416417
c(names(Schema$layout$layoutAttributes), c("barmode", "bargap", "mapType")),
417418
"layout"
418419
)
420+
attrs_name_check(
421+
names(p$x$config),
422+
names(Schema$config),
423+
"config"
424+
)
419425
for (tr in seq_along(p$x$data)) {
420426
thisTrace <- p$x$data[[tr]]
421427
attrSpec <- Schema$traces[[thisTrace$type %||% "scatter"]]$attributes
@@ -435,7 +441,7 @@ verify_attr_names <- function(p) {
435441
verify_attr_spec <- function(p) {
436442
if (!is.null(p$x$layout)) {
437443
p$x$layout <- verify_attr(
438-
p$x$layout, Schema$layout$layoutAttributes
444+
p$x$layout, Schema$layout$layoutAttributes, layoutAttr = TRUE
439445
)
440446
}
441447
for (tr in seq_along(p$x$data)) {
@@ -450,7 +456,7 @@ verify_attr_spec <- function(p) {
450456
p
451457
}
452458

453-
verify_attr <- function(proposed, schema) {
459+
verify_attr <- function(proposed, schema, layoutAttr = FALSE) {
454460
for (attr in names(proposed)) {
455461
attrSchema <- schema[[attr]] %||% schema[[sub("[0-9]+$", "", attr)]]
456462
# if schema is missing (i.e., this is an un-official attr), move along
@@ -479,8 +485,10 @@ verify_attr <- function(proposed, schema) {
479485
}
480486

481487
# tag 'src-able' attributes (needed for api_create())
488+
# note that layout has 'src-able' attributes that shouldn't
489+
# be turned into grids https://github.com/ropensci/plotly/pull/1489
482490
isSrcAble <- !is.null(schema[[paste0(attr, "src")]]) && length(proposed[[attr]]) > 1
483-
if (isDataArray || isSrcAble) {
491+
if ((isDataArray || isSrcAble) && !isTRUE(layoutAttr)) {
484492
proposed[[attr]] <- structure(proposed[[attr]], apiSrc = TRUE)
485493
}
486494

@@ -508,7 +516,7 @@ verify_attr <- function(proposed, schema) {
508516

509517
# do the same for "sub-attributes"
510518
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
511-
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]])
519+
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]], layoutAttr = layoutAttr)
512520
}
513521
}
514522

@@ -517,6 +525,10 @@ verify_attr <- function(proposed, schema) {
517525

518526
attrs_name_check <- function(proposedAttrs, validAttrs, type = "scatter") {
519527
illegalAttrs <- setdiff(proposedAttrs, validAttrs)
528+
if ("titlefont" %in% illegalAttrs) {
529+
warning("The titlefont attribute is deprecated. Use title = list(font = ...) instead.", call. = FALSE)
530+
illegalAttrs <- setdiff(illegalAttrs, "titlefont")
531+
}
520532
if (length(illegalAttrs)) {
521533
warning("'", type, "' objects don't have these attributes: '",
522534
paste(illegalAttrs, collapse = "', '"), "'\n",

0 commit comments

Comments
 (0)