Skip to content

Commit 8200dbe

Browse files
committed
Merge branch 'master' of https://github.com/ropensci/plotly into ropensci-master
2 parents 32dde41 + c19594b commit 8200dbe

File tree

28 files changed

+316
-127
lines changed

28 files changed

+316
-127
lines changed

DESCRIPTION

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via 'plotly.js'
3-
Version: 4.9.2.1
3+
Version: 4.9.2.9000
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "[email protected]", comment = c(ORCID = "0000-0002-4958-2844")),
66
person("Chris", "Parmer", role = "aut",
@@ -26,7 +26,7 @@ Depends:
2626
Imports:
2727
tools,
2828
scales,
29-
httr,
29+
httr (>= 1.3.0),
3030
jsonlite (>= 1.6),
3131
magrittr,
3232
digest,
@@ -72,6 +72,10 @@ Suggests:
7272
plotlyGeoAssets,
7373
forcats
7474
LazyData: true
75+
<<<<<<< HEAD
7576
RoxygenNote: 7.0.2
77+
=======
78+
RoxygenNote: 7.1.0
79+
>>>>>>> c19594b1fb54b28952895344fec3ad0060a1c646
7680
Encoding: UTF-8
7781
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ importFrom(htmlwidgets,saveWidget)
241241
importFrom(htmlwidgets,shinyRenderWidget)
242242
importFrom(htmlwidgets,shinyWidgetOutput)
243243
importFrom(htmlwidgets,sizingPolicy)
244-
importFrom(httr,GET)
245-
importFrom(httr,PATCH)
246-
importFrom(httr,POST)
244+
importFrom(httr,RETRY)
247245
importFrom(httr,add_headers)
246+
importFrom(httr,authenticate)
248247
importFrom(httr,config)
249248
importFrom(httr,content)
250249
importFrom(httr,stop_for_status)
251250
importFrom(httr,warn_for_status)
251+
importFrom(httr,write_disk)
252252
importFrom(jsonlite,parse_json)
253253
importFrom(jsonlite,read_json)
254254
importFrom(jsonlite,toJSON)

NEWS.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,60 @@ This is minor patch release with a few minor bug fixes and updates test expectat
3535

3636
## BUG FIXES
3737

38+
=======
39+
# 4.9.2.9000
40+
41+
## Changes to plotly.js
42+
43+
* This version of the R package upgrades the version of the underlying plotly.js library from v1.52.2 to v1.54.1. This includes many bug fixes and improvements. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes.
44+
45+
## IMPROVEMENTS
46+
47+
* All HTTP requests are now retried upon failure (#1656)
48+
49+
## BUG FIXES
50+
51+
* `ggplotly()` now handles `element_blank()` and `factor()` labels in positional scales correctly (#1731 and #1772).
52+
53+
# 4.9.2.1
54+
55+
This is minor patch release with a few minor bug fixes and updates test expectations in anticipation of new R 4.0 defaults.
56+
57+
## BUG FIXES
58+
59+
* Fixes rendering issues non-HTML **rmarkdown** output formats, which was introduced in the 4.9.2 release (#1702).
60+
* Fixes a `ggplotly()` bug in axis tick translation (#1725, #1721).
61+
* `plot_mapbox()` now correctly defaults to a scattermapbox trace (unless z is present, then it defaults to choroplethmapbox) (#1707).
62+
* `ggplotly()` now correctly resolves overlapping axis tick text in `coord_sf()` (#1673).
63+
* A false-positive warning is no longer thrown when attempting to cast `toWebGL()` (#1569).
64+
65+
# 4.9.2
66+
67+
## Changes to plotly.js
68+
69+
* This version of the R package upgrades the version of the underlying plotly.js library from v1.49.4 to v1.52.2. This includes many bug fixes, improvements, as well as 2 new trace types: `treemap` and `image`. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes.
70+
71+
## IMPROVEMENTS
72+
73+
* The `add_image()` function was added to make it easier to create image traces via `raster` objects.
74+
75+
## BUG FIXES
76+
77+
* `add_sf()`/`geom_sf()` now correctly handle geometry columns that are named something other than `"geometry"` (#1659).
78+
* Specifying an english locale no longer results in error (#1686).
79+
80+
# 4.9.1
81+
82+
## Changes to plotly.js
83+
84+
* This version of the R package upgrades the version of the underlying plotly.js library from v1.46.1 to v1.49.4. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes.
85+
86+
## IMPROVEMENTS
87+
88+
* `event_data()` gains support for the `plotly_sunburstclick` event (#1648)
89+
90+
## BUG FIXES
91+
3892
* Fixed an issue with correctly capturing the return value of user-expressions to `renderPlotly()` (#1528).
3993
* Fixed a resizing issue where graphs could be incorrectly resized to their initial size in some cases (#1553).
4094
* `ggplotly()` now positions the x-axis in the last column of a `facet_wrap()` properly (#1501).

R/api_exports.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
#' @param endpoint the endpoint (i.e., location) for the request.
3232
#' To see a list of all available endpoints, call `api()`.
3333
#' Any relevant query parameters should be included here (see examples).
34-
#' @param verb name of the HTTP verb to use (as in, [httr::VERB()]).
35-
#' @param body body of the HTTP request(as in, [httr::VERB()]).
34+
#' @param verb name of the HTTP verb to use (as in, [httr::RETRY()]).
35+
#' @param body body of the HTTP request(as in, [httr::RETRY()]).
3636
#' If this value is not already converted to JSON
3737
#' (via [jsonlite::toJSON()]), it uses the internal `to_JSON()`
3838
#' to ensure values are "automatically unboxed" (i.e., vec.
3939
#'
4040
#' @param ... For `api()`, these arguments are passed onto
41-
#' [httr::VERB()]. For `api_create()`, these arguments are
41+
#' [httr::RETRY()]. For `api_create()`, these arguments are
4242
#' included in the body of the HTTP request.
4343
#'
4444
#' @export
@@ -187,9 +187,16 @@ api <- function(endpoint = "/", verb = "GET", body = NULL, ...) {
187187
body <- to_JSON(body)
188188
}
189189

190-
resp <- httr::VERB(
191-
verb = verb, url = url, api_headers(), api_auth(),
192-
body = body, ...
190+
resp <- httr::RETRY(
191+
verb = verb,
192+
url = url,
193+
api_headers(),
194+
api_auth(),
195+
body = body,
196+
times = 5,
197+
terminate_on = c(400, 401, 403, 404),
198+
terminate_on_success = TRUE,
199+
...
193200
)
194201

195202
structure(process(resp), class = "api")

R/ggplotly.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ggplotly.ggmatrix <- function(p = ggplot2::last_plot(), width = NULL,
127127
titleY = TRUE, titleX = TRUE) %>%
128128
hide_legend() %>%
129129
layout(dragmode = "select")
130-
if (nchar(p$title %||% "") > 0) {
130+
if (robust_nchar(p$title) > 0) {
131131
s <- layout(s, title = p$title)
132132
}
133133
for (i in seq_along(p$xAxisLabels)) {
@@ -436,7 +436,7 @@ gg2list <- function(p, width = NULL, height = NULL,
436436
font = text2font(theme$text)
437437
)
438438
# main plot title
439-
if (nchar(plot$labels$title %||% "") > 0) {
439+
if (robust_nchar(plot$labels$title) > 0) {
440440
gglayout$title <- list(
441441
text = faced(plot$labels$title, theme$plot.title$face),
442442
font = text2font(theme$plot.title),
@@ -567,7 +567,7 @@ gg2list <- function(p, width = NULL, height = NULL,
567567
# allocate enough space for the _longest_ text label
568568
axisTextX <- theme[["axis.text.x"]] %||% theme[["axis.text"]]
569569
labz <- unlist(lapply(layout$panel_params, function(pp) { pp[["x"]]$get_labels %()% pp$x.labels }))
570-
lab <- labz[which.max(nchar(labz))]
570+
lab <- longest_element(labz)
571571
panelMarginY <- panelMarginY + axisTicksX +
572572
bbox(lab, axisTextX$angle, unitConvert(axisTextX, "npc", "height"))[["height"]]
573573
}
@@ -579,7 +579,7 @@ gg2list <- function(p, width = NULL, height = NULL,
579579
# allocate enough space for the _longest_ text label
580580
axisTextY <- theme[["axis.text.y"]] %||% theme[["axis.text"]]
581581
labz <- unlist(lapply(layout$panel_params, function(pp) { pp[["y"]]$get_labels %()% pp$y.labels }))
582-
lab <- labz[which.max(nchar(labz))]
582+
lab <- longest_element(labz)
583583
panelMarginX <- panelMarginX + axisTicksY +
584584
bbox(lab, axisTextY$angle, unitConvert(axisTextY, "npc", "width"))[["width"]]
585585
}
@@ -693,8 +693,9 @@ gg2list <- function(p, width = NULL, height = NULL,
693693
tickvals <- rng[[xy]]$break_positions %()% rng[[paste0(xy, ".major")]]
694694

695695
# https://github.com/tidyverse/ggplot2/pull/3566#issuecomment-565085809
696-
ticktext <- ticktext[!is.na(ticktext)]
697-
tickvals <- tickvals[!is.na(tickvals)]
696+
hasTickText <- !(is.na(ticktext) | is.na(tickvals))
697+
ticktext <- ticktext[hasTickText]
698+
tickvals <- tickvals[hasTickText]
698699

699700
axisObj <- list(
700701
# TODO: log type?
@@ -805,15 +806,15 @@ gg2list <- function(p, width = NULL, height = NULL,
805806

806807
# do some stuff that should be done once for the entire plot
807808
if (i == 1) {
808-
axisTickText <- axisObj$ticktext[which.max(nchar(axisObj$ticktext))]
809+
axisTickText <- longest_element(axisObj$ticktext)
809810
side <- if (xy == "x") "b" else "l"
810811
# account for axis ticks, ticks text, and titles in plot margins
811812
# (apparently ggplot2 doesn't support axis.title/axis.text margins)
812813
gglayout$margin[[side]] <- gglayout$margin[[side]] + axisObj$ticklen +
813814
bbox(axisTickText, axisObj$tickangle, axisObj$tickfont$size)[[type]] +
814815
bbox(axisTitleText, axisTitle$angle, unitConvert(axisTitle, "pixels", type))[[type]]
815816

816-
if (nchar(axisTitleText) > 0) {
817+
if (robust_nchar(axisTitleText) > 0) {
817818
axisTextSize <- unitConvert(axisText, "npc", type)
818819
axisTitleSize <- unitConvert(axisTitle, "npc", type)
819820
offset <-
@@ -835,7 +836,7 @@ gg2list <- function(p, width = NULL, height = NULL,
835836
}
836837
# facets have multiple axis objects, but only one title for the plot,
837838
# so we empty the titles and try to draw the title as an annotation
838-
if (nchar(axisTitleText) > 0) {
839+
if (robust_nchar(axisTitleText) > 0) {
839840
# npc is on a 0-1 scale of the _entire_ device,
840841
# but these units _should_ be wrt to the plotting region
841842
# multiplying the offset by 2 seems to work, but this is a terrible hack
@@ -872,7 +873,7 @@ gg2list <- function(p, width = NULL, height = NULL,
872873
)
873874
if (is_blank(theme[["strip.text.x"]])) col_txt <- ""
874875
if (inherits(plot$facet, "FacetGrid") && lay$ROW != 1) col_txt <- ""
875-
if (nchar(col_txt) > 0) {
876+
if (robust_nchar(col_txt) > 0) {
876877
col_lab <- make_label(
877878
col_txt, x = mean(xdom), y = max(ydom),
878879
el = theme[["strip.text.x"]] %||% theme[["strip.text"]],
@@ -889,7 +890,7 @@ gg2list <- function(p, width = NULL, height = NULL,
889890
)
890891
if (is_blank(theme[["strip.text.y"]])) row_txt <- ""
891892
if (inherits(plot$facet, "FacetGrid") && lay$COL != nCols) row_txt <- ""
892-
if (nchar(row_txt) > 0) {
893+
if (robust_nchar(row_txt) > 0) {
893894
row_lab <- make_label(
894895
row_txt, x = max(xdom), y = mean(ydom),
895896
el = theme[["strip.text.y"]] %||% theme[["strip.text"]],
@@ -1179,7 +1180,7 @@ is_blank <- function(x) {
11791180
# given text, and x/y coordinates on 0-1 scale,
11801181
# convert ggplot2::element_text() to plotly annotation
11811182
make_label <- function(txt = "", x, y, el = ggplot2::element_text(), ...) {
1182-
if (is_blank(el) || is.null(txt) || nchar(txt) == 0 || length(txt) == 0) {
1183+
if (is_blank(el) || is.null(txt) || robust_nchar(txt) == 0 || length(txt) == 0) {
11831184
return(NULL)
11841185
}
11851186
angle <- el$angle %||% 0
@@ -1214,9 +1215,9 @@ has_facet <- function(x) {
12141215

12151216
bbox <- function(txt = "foo", angle = 0, size = 12) {
12161217
# assuming the horizontal size of a character is roughly half of the vertical
1217-
n <- nchar(txt)
1218+
n <- robust_nchar(txt)
12181219
if (sum(n) == 0) return(list(height = 0, width = 0))
1219-
w <- size * (nchar(txt) / 2)
1220+
w <- size * (robust_nchar(txt) / 2)
12201221
angle <- abs(angle %||% 0)
12211222
# do the sensible thing in the majority of cases
12221223
if (angle == 0) return(list(height = size, width = w))

R/imports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @importFrom tidyr unnest
77
#' @importFrom viridisLite viridis
88
#' @importFrom jsonlite toJSON parse_json read_json
9-
#' @importFrom httr GET POST PATCH content config add_headers stop_for_status warn_for_status
9+
#' @importFrom httr RETRY content config add_headers authenticate stop_for_status warn_for_status write_disk
1010
#' @importFrom htmlwidgets createWidget sizingPolicy saveWidget onRender prependContent
1111
#' @importFrom lazyeval f_eval is_formula all_dots is_lang f_new
1212
#' @importFrom tibble as_tibble

R/orca.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ orca_serve <- function(port = 5151, mathjax = FALSE, safe = FALSE, request_limit
192192
height = height,
193193
scale = scale
194194
)
195-
res <- httr::POST(
196-
paste0("http://127.0.0.1:", port),
197-
body = to_JSON(bod)
195+
res <- httr::RETRY(
196+
verb = "POST",
197+
url = paste0("http://127.0.0.1:", port),
198+
body = to_JSON(bod),
199+
times = 5,
200+
terminate_on = c(400, 401, 403, 404),
201+
terminate_on_success = TRUE
198202
)
199203
httr::stop_for_status(res)
200204
httr::warn_for_status(res)

R/plotly.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ as_widget <- function(x, ...) {
430430
# we shouldn't need it because Object.setPrototypeOf() is pretty widely supported
431431
# https://github.com/plotly/plotly.js/issues/4556#issuecomment-583061419
432432
# https://caniuse.com/#search=setPrototypeOf
433-
if (isTRUE(getOption("shiny.testmode"))) {
433+
if (needsPrototypePolyfill()) {
434434
list(setPrototypeOfPolyfill())
435435
},
436436
list(typedArrayPolyfill()),
@@ -441,6 +441,18 @@ as_widget <- function(x, ...) {
441441
)
442442
}
443443

444+
needsPrototypePolyfill <- function() {
445+
if (isTRUE(getOption("shiny.testmode"))) {
446+
return(TRUE)
447+
}
448+
449+
if (isTRUE(getOption("knitr.in.progress"))) {
450+
return(!knitr::is_html_output())
451+
}
452+
453+
return(FALSE)
454+
}
455+
444456
setPrototypeOfPolyfill <- function() {
445457
htmltools::htmlDependency(
446458
name = "setprototypeof",
@@ -466,7 +478,7 @@ typedArrayPolyfill <- function() {
466478
plotlyMainBundle <- function() {
467479
htmltools::htmlDependency(
468480
name = "plotly-main",
469-
version = "1.52.2",
481+
version = "1.54.1",
470482
package = "plotly",
471483
src = dependency_dir("plotlyjs"),
472484
script = "plotly-latest.min.js",

R/plotly_IMAGE.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @param format The desired image format 'png', 'jpeg', 'svg', 'pdf', 'eps', or 'webp'
1010
#' @param scale Both png and jpeg formats will be scaled beyond the specified width and height by this number.
1111
#' @param out_file A filename for writing the image to a file.
12-
#' @param ... arguments passed onto `httr::POST`
12+
#' @param ... arguments passed onto `httr::RETRY`
1313
#' @export
1414
#' @examples \dontrun{
1515
#' p <- plot_ly(x = 1:10)
@@ -34,9 +34,16 @@ plotly_IMAGE <- function(x, width = 1000, height = 500, format = "png",
3434
filename = Sys.time()
3535
)
3636
base_url <- file.path(get_domain("api"), "v2", "images")
37-
resp <- httr::POST(
38-
base_url, body = to_JSON(bod), api_headers(), api_auth(),
39-
if (!missing(out_file)) httr::write_disk(out_file, overwrite = TRUE),
37+
resp <- httr::RETRY(
38+
verb = "POST",
39+
url = base_url,
40+
body = to_JSON(bod),
41+
times = 5,
42+
terminate_on = c(400, 401, 403, 404),
43+
terminate_on_success = TRUE,
44+
api_headers(),
45+
api_auth(),
46+
if (!missing(out_file)) httr::write_disk(out_file, overwrite = TRUE),
4047
...
4148
)
4249
con <- process(append_class(resp, "api_image"))

R/signup.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ signup <- function(username, email, save = TRUE) {
4545
version = as.character(packageVersion("plotly"))
4646
)
4747
base_url <- file.path(get_domain(), "apimkacct")
48-
resp <- httr::POST(base_url, body = bod)
48+
resp <- httr::RETRY(
49+
verb = "POST",
50+
base_url,
51+
body = bod,
52+
times = 5,
53+
terminate_on = c(400, 401, 403, 404),
54+
terminate_on_success = TRUE
55+
)
4956
con <- process(append_class(resp, "signup"))
5057
if (save) {
5158
# store API key as an environment variable in .Rprofile

0 commit comments

Comments
 (0)