Skip to content

Upgrade to v1.46 #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fa24f74
upgrade to plotly.js v1.43.2
cpsievert Jan 9, 2019
a32a03e
remove config()'s cloud argument in favor of plotly.js' new config at…
cpsievert Jan 11, 2019
e91d2d4
fix typo in ternary demo
cpsievert Jan 21, 2019
7a27932
validate new visual baselines
cpsievert Jan 21, 2019
b9a5c54
merge with master; validate new baselines
cpsievert Jan 22, 2019
d35b7af
merge conflicts
cpsievert Feb 8, 2019
2a25096
upgrade to plotly.js v1.44.3
cpsievert Feb 9, 2019
2939262
validate new baselines
cpsievert Feb 9, 2019
36b4215
upgrade to plotly.js v1.45.3
cpsievert Mar 19, 2019
1992179
Throw more informative warning if titlefont is detected and move from…
cpsievert Apr 1, 2019
e830583
actually remove cloud argument from config()
cpsievert Apr 1, 2019
cc00623
add name checking for config attributes
cpsievert Apr 1, 2019
0bfa6fa
fix test expectation
cpsievert Apr 2, 2019
30d05bb
upgrade to v1.46.0
cpsievert Apr 2, 2019
ae96a8b
make sure sunburst default to white stroke
cpsievert Apr 2, 2019
93c03ae
add some visual tests of the new trace types
cpsievert Apr 2, 2019
e690ae9
Add isosurface to non-tidy traces
cpsievert Apr 2, 2019
bacfc1d
merge conflicts and validate v1.46 baseline changes
cpsievert Apr 2, 2019
3e0a6d2
officially add isosurface visual test; document
cpsievert Apr 2, 2019
1c7b107
Merge branch 'master' into v1.46
cpsievert Apr 2, 2019
2fe5cfc
avoid use of layout.axisid.titlefont in ggplotly()
cpsievert Apr 2, 2019
c949e42
translate hjust in plot.title theme to layout.title's new placement API
cpsievert Apr 2, 2019
6784580
update test expectations
cpsievert Apr 2, 2019
ac57d36
re-surface an old test
cpsievert Apr 2, 2019
d8010d9
validate baselines again
cpsievert Apr 2, 2019
7617ca3
update shinytest baselines
cpsievert Apr 2, 2019
9063b24
add news point about title alignment in ggplotly
cpsievert Apr 3, 2019
25d721f
add waterfall to finance bundle and isosurface to gl3d
cpsievert Apr 3, 2019
52bde42
add note about ggplotly() now returning different title attributes
cpsievert Apr 3, 2019
95cc431
permalink to isosurface mock; skip on CRAN
cpsievert Apr 3, 2019
fea72b6
maintain backwards-compatibility for cloud
cpsievert Apr 3, 2019
bbd2758
have sunburst/pie stroke default to paper_bgcolor
cpsievert Apr 3, 2019
de622a0
fix scoping
cpsievert Apr 3, 2019
11ba0e0
throw warning if cloud is specified; add tests
cpsievert Apr 3, 2019
2124bbd
validate changes in shinytest json
cpsievert Apr 3, 2019
93fbce8
merge conflicts
cpsievert Apr 3, 2019
69fe559
skip isosurface on travis (I can't seem to replicate)
cpsievert Apr 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 13 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# 4.8.0.9000

## Changes to plotly.js

* 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:
* New trace types: `sunburst`, `waterfall`, `isosurface`.
* 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.
* 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.

## NEW FEATURES & IMPROVEMENTS

* Upgraded to plotly.js v1.42.5.
* 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)):
* 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")`,
* 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`.
Expand All @@ -14,15 +20,19 @@
* The `orca()` function now supports conversion of much larger figures (#1322) and works without a mapbox api token (#1314).
* The `orca_serve()` function was added for efficient exporting of many plotly graphs. For examples, see `help(orca_serve)`.
* The `orca()` function gains new arguments `more_args` and `...` for finer control over the underlying system commands.


* `ggplotly()` now respects horizontal alignment of **ggplot2** titles (e.g., `ggplotly(qplot(1:10) + ggtitle("A title") + theme(plot.title = element_text(hjust = 1)))`).
* **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).
* 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).
* 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")`.
* 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.
* An informative warning is now thrown if invalid argument names are supplied to `config()`.

## CHANGES

* The 'collaborate' button no longer appears in the modebar, and as a result, the `config()` function no longer has a `collaborate` argument.
* The 'collaborate' button no longer appears in the modebar, and is longer supported, so the `config()` function no longer has a `collaborate` argument.
* The `cloud` argument is now deprecated and will be removed in a future version. Use `showSendToCloud` instead.
* `ggplotly()` now translates title information to `layout.title.text` (instead of `layout.title`) and `layout.title.font` (instead of `layout.titlefont`)

## BUG FIXES

Expand Down
19 changes: 14 additions & 5 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,15 @@ gg2list <- function(p, width = NULL, height = NULL,
)
# main plot title
if (nchar(plot$labels$title %||% "") > 0) {
gglayout$title <- faced(plot$labels$title, theme$plot.title$face)
gglayout$titlefont <- text2font(theme$plot.title)
gglayout$margin$t <- gglayout$margin$t + gglayout$titlefont$size
gglayout$title <- list(
text = faced(plot$labels$title, theme$plot.title$face),
font = text2font(theme$plot.title),
# don't translate vjust to y since they since have very different meaning...
# y is allowed to span the paper coordinate whereas vjust it local to it's grob
x = theme$plot.title$hjust,
xref = "paper"
)
gglayout$margin$t <- gglayout$margin$t + gglayout$title$font$size
}
# ensure there's enough space for the modebar (this is based on a height of 1em)
# https://github.com/plotly/plotly.js/blob/dd1547/src/components/modebar/index.js#L171
Expand Down Expand Up @@ -695,8 +701,11 @@ gg2list <- function(p, width = NULL, height = NULL,
gridwidth = unitConvert(panelGrid, "pixels", type),
zeroline = FALSE,
anchor = anchor,
title = faced(axisTitleText, axisTitle$face),
titlefont = text2font(axisTitle)
# layout.axisid.title don't yet support alignment :(
title = list(
text = faced(axisTitleText, axisTitle$face),
font = text2font(axisTitle)
)
)

# set scaleanchor/scaleratio if these are fixed coordinates
Expand Down
8 changes: 5 additions & 3 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
#' @param p a plotly object
#' @param ... these arguments are documented at
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js}
#' @param cloud include the send data to cloud button?
#' @param cloud deprecated. Use `showSendToCloud` instead.
#' @param showSendToCloud include the send data to cloud button?
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info.
#' @param mathjax add [MathJax rendering support](https://github.com/plotly/plotly.js/tree/master/dist#to-support-mathjax).
#' If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for
Expand Down Expand Up @@ -130,7 +131,7 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
#' config(p, locale = "zh-CN")
#'

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

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

p
}
7 changes: 5 additions & 2 deletions R/partial_bundles.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ verify_partial_bundle <- function(p) {
# verify that this partial bundle actually supports this viz
# (at this point, bundleType should never be 'auto' or 'main')
missingTypes <- setdiff(types, bundleTraceMap[[bundleType]])

if (length(missingTypes)) {
msg <- sprintf(
"The '%s' bundle supports the following trace types: '%s'.\n\n This plotly visualization contains the following trace types: '%s'",
Expand Down Expand Up @@ -188,7 +189,8 @@ bundleTraceMap <- list(
"scatter3d",
"surface",
"mesh3d",
"cone"
"cone",
"isosurface"
),
gl2d = c(
"scatter",
Expand All @@ -209,6 +211,7 @@ bundleTraceMap <- list(
"pie",
"histogram",
"ohlc",
"candlestick"
"candlestick",
"waterfall"
)
)
4 changes: 1 addition & 3 deletions R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,10 @@ typedArrayPolyfill <- function() {
)
}

# TODO: suggest a plotlyBundles package that has trace-level bundles
# and bundle size at print time.
plotlyMainBundle <- function() {
htmltools::htmlDependency(
name = "plotly-main",
version = "1.42.5",
version = "1.46.1",
package = "plotly",
src = dependency_dir("plotlyjs"),
script = "plotly-latest.min.js",
Expand Down
17 changes: 17 additions & 0 deletions R/plotly_build.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) {
trace <- verify_type(trace)
# verify orientation of boxes/bars
trace <- verify_orientation(trace)
# supply sensible defaults based on trace type
trace <- coerce_attr_defaults(trace, p$x$layout)



# attach crosstalk info, if necessary
if (crosstalk_key() %in% names(dat) && isTRUE(trace[["inherit"]] %||% TRUE)) {
Expand Down Expand Up @@ -1018,3 +1022,16 @@ has_fill <- function(trace) {
if (has_fillcolor && isTRUE(fill != "none")) return(TRUE)
FALSE
}

# ensure we've set a sensible trace defaults
# based on the trace type
coerce_attr_defaults <- function(trace, layout) {
if (trace[["type"]] %in% c("sunburst", "pie")) {
# As of v1.46.1, paper_bgcolor defaults to '#fff' which
# col2rgb() can't parse, but expands to '#ffffff'
# https://stackoverflow.com/a/2899224/1583084
bgcolor <- layout$paper_bgcolor %||% "#ffffff"
trace$stroke <- trace[["stroke"]] %||% default(I(bgcolor))
}
trace
}
Binary file modified R/sysdata.rda
Binary file not shown.
12 changes: 11 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ getLevels <- function(x) {
tryNULL <- function(expr) tryCatch(expr, error = function(e) NULL)

# Don't attempt to do "tidy" data training on these trace types
# Note that non-tidy traces expect/anticipate data_array's of varying lengths
is_tidy <- function(trace) {
type <- trace[["type"]] %||% "scatter"
!type %in% c(
"mesh3d", "heatmap", "histogram2d",
"mesh3d", "heatmap", "histogram2d", "isosurface",
"histogram2dcontour", "contour", "surface"
)
}
Expand Down Expand Up @@ -416,6 +417,11 @@ verify_attr_names <- function(p) {
c(names(Schema$layout$layoutAttributes), c("barmode", "bargap", "mapType")),
"layout"
)
attrs_name_check(
names(p$x$config),
names(Schema$config),
"config"
)
for (tr in seq_along(p$x$data)) {
thisTrace <- p$x$data[[tr]]
attrSpec <- Schema$traces[[thisTrace$type %||% "scatter"]]$attributes
Expand Down Expand Up @@ -519,6 +525,10 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) {

attrs_name_check <- function(proposedAttrs, validAttrs, type = "scatter") {
illegalAttrs <- setdiff(proposedAttrs, validAttrs)
if ("titlefont" %in% illegalAttrs) {
warning("The titlefont attribute is deprecated. Use title = list(font = ...) instead.", call. = FALSE)
illegalAttrs <- setdiff(illegalAttrs, "titlefont")
}
if (length(illegalAttrs)) {
warning("'", type, "' objects don't have these attributes: '",
paste(illegalAttrs, collapse = "', '"), "'\n",
Expand Down
34 changes: 19 additions & 15 deletions inst/examples/shiny/event_data/tests/mytest-expected/001.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@
"gridwidth": 0.66417600664176,
"zeroline": false,
"anchor": "y",
"title": "mpg",
"titlefont": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
"title": {
"text": "mpg",
"font": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
}
},
"hoverformat": ".2f"
},
Expand Down Expand Up @@ -300,11 +302,13 @@
"gridwidth": 0.66417600664176,
"zeroline": false,
"anchor": "x",
"title": "wt",
"titlefont": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
"title": {
"text": "wt",
"font": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
}
},
"hoverformat": ".2f"
},
Expand Down Expand Up @@ -344,7 +348,7 @@
},
"config": {
"doubleClick": "reset",
"cloud": false
"showSendToCloud": false
},
"source": "A",
"shinyEvents": [
Expand Down Expand Up @@ -423,9 +427,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.42.5",
"version": "1.46.1",
"src": {
"href": "plotly-htmlwidgets-css-1.42.5"
"href": "plotly-htmlwidgets-css-1.46.1"
},
"meta": null,
"script": null,
Expand All @@ -436,9 +440,9 @@
},
{
"name": "plotly-main",
"version": "1.42.5",
"version": "1.46.1",
"src": {
"href": "plotly-main-1.42.5"
"href": "plotly-main-1.46.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Binary file modified inst/examples/shiny/event_data/tests/mytest-expected/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 19 additions & 15 deletions inst/examples/shiny/event_data/tests/mytest-expected/002.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,13 @@
"gridwidth": 0.66417600664176,
"zeroline": false,
"anchor": "y",
"title": "mpg",
"titlefont": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
"title": {
"text": "mpg",
"font": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
}
},
"hoverformat": ".2f"
},
Expand Down Expand Up @@ -317,11 +319,13 @@
"gridwidth": 0.66417600664176,
"zeroline": false,
"anchor": "x",
"title": "wt",
"titlefont": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
"title": {
"text": "wt",
"font": {
"color": "rgba(0,0,0,1)",
"family": "",
"size": 14.6118721461187
}
},
"hoverformat": ".2f"
},
Expand Down Expand Up @@ -361,7 +365,7 @@
},
"config": {
"doubleClick": "reset",
"cloud": false
"showSendToCloud": false
},
"source": "A",
"shinyEvents": [
Expand Down Expand Up @@ -440,9 +444,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.42.5",
"version": "1.46.1",
"src": {
"href": "plotly-htmlwidgets-css-1.42.5"
"href": "plotly-htmlwidgets-css-1.46.1"
},
"meta": null,
"script": null,
Expand All @@ -453,9 +457,9 @@
},
{
"name": "plotly-main",
"version": "1.42.5",
"version": "1.46.1",
"src": {
"href": "plotly-main-1.42.5"
"href": "plotly-main-1.46.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Binary file modified inst/examples/shiny/event_data/tests/mytest-expected/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading