Skip to content

Commit bac2203

Browse files
committed
Merge branch 'master' into wrap-fct-lbls
2 parents 67c8f12 + c19594b commit bac2203

File tree

345 files changed

+532
-412
lines changed

Some content is hidden

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

345 files changed

+532
-412
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Depends:
2828
Imports:
2929
tools,
3030
scales,
31-
httr,
31+
httr (>= 1.3.0),
3232
jsonlite (>= 1.6),
3333
magrittr,
3434
digest,

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# 4.9.2.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.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.
6+
37
## IMPROVEMENTS
48

9+
* All HTTP requests are now retried upon failure (#1656)
10+
511
## BUG FIXES
612

13+
* `ggplotly()` now handles `element_blank()` and `factor()` labels in positional scales correctly (#1731 and #1772).
14+
715
# 4.9.2.1
816

917
This is minor patch release with a few minor bug fixes and updates test expectations in anticipation of new R 4.0 defaults.

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: 12 additions & 12 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
}
@@ -806,15 +806,15 @@ gg2list <- function(p, width = NULL, height = NULL,
806806

807807
# do some stuff that should be done once for the entire plot
808808
if (i == 1) {
809-
axisTickText <- axisObj$ticktext[which.max(nchar(axisObj$ticktext))]
809+
axisTickText <- longest_element(axisObj$ticktext)
810810
side <- if (xy == "x") "b" else "l"
811811
# account for axis ticks, ticks text, and titles in plot margins
812812
# (apparently ggplot2 doesn't support axis.title/axis.text margins)
813813
gglayout$margin[[side]] <- gglayout$margin[[side]] + axisObj$ticklen +
814814
bbox(axisTickText, axisObj$tickangle, axisObj$tickfont$size)[[type]] +
815815
bbox(axisTitleText, axisTitle$angle, unitConvert(axisTitle, "pixels", type))[[type]]
816816

817-
if (nchar(axisTitleText) > 0) {
817+
if (robust_nchar(axisTitleText) > 0) {
818818
axisTextSize <- unitConvert(axisText, "npc", type)
819819
axisTitleSize <- unitConvert(axisTitle, "npc", type)
820820
offset <-
@@ -836,7 +836,7 @@ gg2list <- function(p, width = NULL, height = NULL,
836836
}
837837
# facets have multiple axis objects, but only one title for the plot,
838838
# so we empty the titles and try to draw the title as an annotation
839-
if (nchar(axisTitleText) > 0) {
839+
if (robust_nchar(axisTitleText) > 0) {
840840
# npc is on a 0-1 scale of the _entire_ device,
841841
# but these units _should_ be wrt to the plotting region
842842
# multiplying the offset by 2 seems to work, but this is a terrible hack
@@ -873,7 +873,7 @@ gg2list <- function(p, width = NULL, height = NULL,
873873
)
874874
if (is_blank(theme[["strip.text.x"]])) col_txt <- ""
875875
if (inherits(plot$facet, "FacetGrid") && lay$ROW != 1) col_txt <- ""
876-
if (nchar(col_txt) > 0) {
876+
if (robust_nchar(col_txt) > 0) {
877877
col_lab <- make_label(
878878
col_txt, x = mean(xdom), y = max(ydom),
879879
el = theme[["strip.text.x"]] %||% theme[["strip.text"]],
@@ -890,7 +890,7 @@ gg2list <- function(p, width = NULL, height = NULL,
890890
)
891891
if (is_blank(theme[["strip.text.y"]])) row_txt <- ""
892892
if (inherits(plot$facet, "FacetGrid") && lay$COL != nCols) row_txt <- ""
893-
if (nchar(row_txt) > 0) {
893+
if (robust_nchar(row_txt) > 0) {
894894
row_lab <- make_label(
895895
row_txt, x = max(xdom), y = mean(ydom),
896896
el = theme[["strip.text.y"]] %||% theme[["strip.text"]],
@@ -1180,7 +1180,7 @@ is_blank <- function(x) {
11801180
# given text, and x/y coordinates on 0-1 scale,
11811181
# convert ggplot2::element_text() to plotly annotation
11821182
make_label <- function(txt = "", x, y, el = ggplot2::element_text(), ...) {
1183-
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) {
11841184
return(NULL)
11851185
}
11861186
angle <- el$angle %||% 0
@@ -1215,9 +1215,9 @@ has_facet <- function(x) {
12151215

12161216
bbox <- function(txt = "foo", angle = 0, size = 12) {
12171217
# assuming the horizontal size of a character is roughly half of the vertical
1218-
n <- nchar(txt)
1218+
n <- robust_nchar(txt)
12191219
if (sum(n) == 0) return(list(height = 0, width = 0))
1220-
w <- size * (nchar(txt) / 2)
1220+
w <- size * (robust_nchar(txt) / 2)
12211221
angle <- abs(angle %||% 0)
12221222
# do the sensible thing in the majority of cases
12231223
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ typedArrayPolyfill <- function() {
478478
plotlyMainBundle <- function() {
479479
htmltools::htmlDependency(
480480
name = "plotly-main",
481-
version = "1.52.2",
481+
version = "1.54.1",
482482
package = "plotly",
483483
src = dependency_dir("plotlyjs"),
484484
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)