diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 66e69dd636..18a9ebf3e8 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -34,7 +34,7 @@ jobs: - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} + # - {os: ubuntu-latest, r: 'oldrel-3'} # dependency issues with oldrel-3 # - {os: ubuntu-latest, r: 'oldrel-4'} # dependency issues with oldrel-4 env: @@ -72,7 +72,8 @@ jobs: - name: Install kaleido if: matrix.config.visual_tests == true run: | - Rscript -e 'library(reticulate); use_python(Sys.which("python")); py_install(c("kaleido", "plotly"))' + # We pin kaleido to v0.2.1 here since >=v1.0 doesn't appear to be correctly rendering some plots + Rscript -e 'library(reticulate); use_python(Sys.which("python")); py_install(c("kaleido==0.2.1", "plotly"))' # Run test() before R CMD check since, for some reason, rcmdcheck::rcmdcheck() skips vdiffr tests - name: Run Tests diff --git a/.gitignore b/.gitignore index 72c3ccb16a..107f4231a2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ Rapp.history *.RData *.Rproj.user *.DS_Store +.venv node_modules/ build_site.R revdep_email.R diff --git a/DESCRIPTION b/DESCRIPTION index 4a4e15a253..b76987291a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -78,7 +78,7 @@ Suggests: rsvg, ggridges LazyData: true -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) Config/Needs/check: diff --git a/NAMESPACE b/NAMESPACE index 1512977bb3..e8ebe444e5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ S3method(linewidth_or_size,default) S3method(linewidth_or_size,element) S3method(plotly_build,"NULL") S3method(plotly_build,gg) +S3method(plotly_build,ggmatrix) S3method(plotly_build,list) S3method(plotly_build,plotly) S3method(print,api) diff --git a/NEWS.md b/NEWS.md index 0b0f1ef121..c01672f5d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# plotly (development version) + +## Improvements + +* `save_image()` now works with kaleido v1.0 and higher. (#2447) + +## Bug fixes + +* `plotly_build()` now works with `ggmatrix` objects (e.g., from `GGally::ggpairs()`). (#2447) + # plotly 4.11.0 ## New features diff --git a/R/kaleido.R b/R/kaleido.R index 2ed9cdb678..9a83124564 100644 --- a/R/kaleido.R +++ b/R/kaleido.R @@ -70,7 +70,7 @@ kaleido <- function(...) { call_env <- rlang::caller_env() - if (!reticulate::py_available()) { + if (!reticulate::py_available(TRUE)) { rlang::abort(c("`{reticulate}` wasn't able to find a Python environment.", i = "If you have an existing Python installation, use `reticulate::use_python()` to inform `{reticulate}` of it.", i = "To have `{reticulate}` install Python for you, `reticulate::install_python()`." @@ -97,6 +97,66 @@ kaleido <- function(...) { } ) + res <- if (is.null(tryNULL(kaleido$scopes))) { + newKaleidoScope(kaleido) + } else { + legacyKaleidoScope(kaleido) + } + + class(res) <- "kaleidoScope" + res +} + +newKaleidoScope <- function(kaleido) { + list( + scopes = NULL, + transform = function(p, file, ..., width = NULL, height = NULL, scale = NULL) { + # Perform JSON conversion exactly how the R package would do it + fig_data <- plotly_build(p)$x[c("data", "layout", "config")] + + # Inject mapbox token into layout.mapbox.accesstoken if available + # We use layout instead of config because Kaleido's parser preserves + # layout but drops config. This handles the case where users set + # MAPBOX_TOKEN env var but don't use plot_mapbox() + mapbox <- Sys.getenv("MAPBOX_TOKEN", NA) + if (!is.na(mapbox) && is.null(fig_data$layout$mapbox$accesstoken)) { + fig_data$layout$mapbox$accesstoken <- mapbox + } + + fig <- to_JSON(fig_data) + + # Write to JSON file + tmp_json <- tempfile(fileext = ".json") + on.exit(unlink(tmp_json)) + writeLines(fig, tmp_json) + + # Import it as a fig (dict) + load_json <- sprintf( + "import json; fig = json.load(open('%s'))", + tmp_json + ) + reticulate::py_run_string(load_json) + + # Gather figure-level options + opts <- list( + format = tools::file_ext(file), + width = reticulate::r_to_py(width), + height = reticulate::r_to_py(height), + scale = reticulate::r_to_py(scale) + ) + + # Pass the R plotly.js bundle path to Kaleido + kopts <- list(plotlyjs = plotlyMainBundlePath()) + + # Write the figure to a file using kaleido + kaleido$write_fig_sync(reticulate::py$fig, file, opts = opts, kopts = kopts) + }, + shutdown = function() {} + ) +} + + +legacyKaleidoScope <- function(kaleido) { py <- reticulate::py scope_name <- paste0("scope_", new_id()) py[[scope_name]] <- kaleido$scopes$plotly$PlotlyScope( @@ -151,7 +211,6 @@ kaleido <- function(...) { reticulate::py_run_string(paste("del", scope_name)) }) - class(res) <- "kaleidoScope" res } diff --git a/R/plotly_build.R b/R/plotly_build.R index d0fb241111..3bdd432601 100644 --- a/R/plotly_build.R +++ b/R/plotly_build.R @@ -37,6 +37,11 @@ plotly_build.gg <- function(p, registerFrames = TRUE) { plotly_build(ggplotly(p)) } +#' @export +plotly_build.ggmatrix <- function(p, registerFrames = TRUE) { + plotly_build(ggplotly(p)) +} + #' @export plotly_build.plotly <- function(p, registerFrames = TRUE) { diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001.json b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001.json index e4e32e11f5..4e1910b54d 100644 --- a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001.json +++ b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001.json @@ -185,9 +185,9 @@ ], "layout": { "margin": { - "t": 25.74124809741248, + "t": 23.305936073059364, "r": 7.3059360730593621, - "b": 39.69558599695587, + "b": 37.260273972602747, "l": 31.415525114155255 }, "plot_bgcolor": "rgba(235,235,235,1)", @@ -239,7 +239,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -252,7 +252,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "y", "title": { @@ -301,7 +301,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -314,7 +314,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "x", "title": { @@ -340,6 +340,7 @@ }, "yref": "paper", "xref": "paper", + "layer": "below", "x0": 0, "x1": 1, "y0": 0, @@ -350,7 +351,7 @@ "legend": { "bgcolor": "rgba(255,255,255,1)", "bordercolor": "transparent", - "borderwidth": 1.8897637795275593, + "borderwidth": 0, "font": { "color": "rgba(0,0,0,1)", "family": "", @@ -445,9 +446,9 @@ }, { "name": "crosstalk", - "version": "1.2.1", + "version": "1.2.2", "src": { - "href": "crosstalk-1.2.1" + "href": "crosstalk-1.2.2" }, "meta": null, "script": "js/crosstalk.min.js", diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001_.png b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001_.png index f844a551f9..346330c011 100644 Binary files a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001_.png and b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/001_.png differ diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002.json b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002.json index 15430c47e8..7ea6ba1b5d 100644 --- a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002.json +++ b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002.json @@ -188,9 +188,9 @@ ], "layout": { "margin": { - "t": 25.74124809741248, + "t": 23.305936073059364, "r": 7.3059360730593621, - "b": 39.69558599695587, + "b": 37.260273972602747, "l": 31.415525114155255 }, "plot_bgcolor": "rgba(235,235,235,1)", @@ -242,7 +242,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -255,7 +255,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "y", "title": { @@ -304,7 +304,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -317,7 +317,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "x", "title": { @@ -343,6 +343,7 @@ }, "yref": "paper", "xref": "paper", + "layer": "below", "x0": 0, "x1": 1, "y0": 0, @@ -353,7 +354,7 @@ "legend": { "bgcolor": "rgba(255,255,255,1)", "bordercolor": "transparent", - "borderwidth": 1.8897637795275593, + "borderwidth": 0, "font": { "color": "rgba(0,0,0,1)", "family": "", @@ -448,9 +449,9 @@ }, { "name": "crosstalk", - "version": "1.2.1", + "version": "1.2.2", "src": { - "href": "crosstalk-1.2.1" + "href": "crosstalk-1.2.2" }, "meta": null, "script": "js/crosstalk.min.js", diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002_.png b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002_.png index b96cc7b25e..39cca6f381 100644 Binary files a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002_.png and b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/002_.png differ diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003.json b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003.json index 91f5634177..3ddab09b34 100644 --- a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003.json +++ b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003.json @@ -192,9 +192,9 @@ ], "layout": { "margin": { - "t": 25.74124809741248, + "t": 23.305936073059364, "r": 7.3059360730593621, - "b": 39.69558599695587, + "b": 37.260273972602747, "l": 31.415525114155255 }, "plot_bgcolor": "rgba(235,235,235,1)", @@ -246,7 +246,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -259,7 +259,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "y", "title": { @@ -308,7 +308,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -321,7 +321,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "x", "title": { @@ -347,6 +347,7 @@ }, "yref": "paper", "xref": "paper", + "layer": "below", "x0": 0, "x1": 1, "y0": 0, @@ -357,7 +358,7 @@ "legend": { "bgcolor": "rgba(255,255,255,1)", "bordercolor": "transparent", - "borderwidth": 1.8897637795275593, + "borderwidth": 0, "font": { "color": "rgba(0,0,0,1)", "family": "", @@ -452,9 +453,9 @@ }, { "name": "crosstalk", - "version": "1.2.1", + "version": "1.2.2", "src": { - "href": "crosstalk-1.2.1" + "href": "crosstalk-1.2.2" }, "meta": null, "script": "js/crosstalk.min.js", diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003_.png b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003_.png index 6c51c45735..8a94c96461 100644 Binary files a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003_.png and b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/003_.png differ diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004.json b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004.json index a5fc81e2ee..e5fc2d1a18 100644 --- a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004.json +++ b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004.json @@ -193,9 +193,9 @@ ], "layout": { "margin": { - "t": 25.74124809741248, + "t": 23.305936073059364, "r": 7.3059360730593621, - "b": 39.69558599695587, + "b": 37.260273972602747, "l": 31.415525114155255 }, "plot_bgcolor": "rgba(235,235,235,1)", @@ -247,7 +247,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -260,7 +260,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "y", "title": { @@ -309,7 +309,7 @@ "ticks": "outside", "tickcolor": "rgba(51,51,51,1)", "ticklen": 3.6529680365296811, - "tickwidth": 0.66417600664176002, + "tickwidth": 0, "showticklabels": true, "tickfont": { "color": "rgba(77,77,77,1)", @@ -322,7 +322,7 @@ "linewidth": 0, "showgrid": true, "gridcolor": "rgba(255,255,255,1)", - "gridwidth": 0.66417600664176002, + "gridwidth": 0, "zeroline": false, "anchor": "x", "title": { @@ -348,6 +348,7 @@ }, "yref": "paper", "xref": "paper", + "layer": "below", "x0": 0, "x1": 1, "y0": 0, @@ -358,7 +359,7 @@ "legend": { "bgcolor": "rgba(255,255,255,1)", "bordercolor": "transparent", - "borderwidth": 1.8897637795275593, + "borderwidth": 0, "font": { "color": "rgba(0,0,0,1)", "family": "", @@ -453,9 +454,9 @@ }, { "name": "crosstalk", - "version": "1.2.1", + "version": "1.2.2", "src": { - "href": "crosstalk-1.2.1" + "href": "crosstalk-1.2.2" }, "meta": null, "script": "js/crosstalk.min.js", diff --git a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004_.png b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004_.png index e424b18f25..e119bcdcc7 100644 Binary files a/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004_.png and b/inst/examples/shiny/event_data/tests/testthat/_snaps/shinytest2/004_.png differ diff --git a/man/TeX.Rd b/man/TeX.Rd index e0ce9772fa..fc72fb1a26 100644 --- a/man/TeX.Rd +++ b/man/TeX.Rd @@ -16,7 +16,7 @@ ensures the provided string is surrounded with \code{$} (this is what plotly.js uses to declare a string as TeX). } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} plot_ly(x = c(1, 2, 3, 4), y = c(1, 4, 9, 16)) \%>\% layout(title = TeX("\\\\text{Some mathjax: }\\\\alpha+\\\\beta x")) \%>\% diff --git a/man/add_data.Rd b/man/add_data.Rd index 892695cd8a..6dac1702ff 100644 --- a/man/add_data.Rd +++ b/man/add_data.Rd @@ -15,7 +15,7 @@ add_data(p, data = NULL) Add data to a plotly visualization } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} plot_ly() \%>\% add_data(economics) \%>\% add_trace(x = ~date, y = ~pce) \dontshow{\}) # examplesIf} diff --git a/man/add_trace.Rd b/man/add_trace.Rd index 5c36652c78..72700f6fde 100644 --- a/man/add_trace.Rd +++ b/man/add_trace.Rd @@ -165,7 +165,7 @@ If \code{z} is a raster object (see \code{\link[=as.raster]{as.raster()}}), the Add trace(s) to a plotly visualization } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # the `plot_ly()` function initiates an object, and if no trace type # is specified, it sets a sensible default diff --git a/man/animation.Rd b/man/animation.Rd index b0b9c9abf7..db96700a09 100644 --- a/man/animation.Rd +++ b/man/animation.Rd @@ -65,7 +65,7 @@ Both the play button and slider component transition between frames according rules specified by \code{\link[=animation_opts]{animation_opts()}}. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} df <- data.frame( x = c(1, 2, 2, 1, 1, 2), diff --git a/man/api.Rd b/man/api.Rd index 6cd01dfb4a..a6ba657ab6 100644 --- a/man/api.Rd +++ b/man/api.Rd @@ -92,7 +92,7 @@ plotly objects via \code{api_download_plot()}/\code{api_download_grid()}. For anything else, use \code{api()}. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ diff --git a/man/as_widget.Rd b/man/as_widget.Rd index 61714c5281..a438aa6651 100644 --- a/man/as_widget.Rd +++ b/man/as_widget.Rd @@ -15,7 +15,7 @@ as_widget(x, ...) Convert a list to a plotly htmlwidget object } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} trace <- list(x = 1, y = 1) obj <- list(data = list(trace), layout = list(title = "my plot")) diff --git a/man/colorbar.Rd b/man/colorbar.Rd index a2f7d53f51..ce9c4978b0 100644 --- a/man/colorbar.Rd +++ b/man/colorbar.Rd @@ -21,7 +21,7 @@ multiple colorbars.} Modify the colorbar } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} p <- plot_ly(mtcars, x = ~wt, y = ~mpg, color = ~cyl) diff --git a/man/config.Rd b/man/config.Rd index e3ac82959f..256ac40b57 100644 --- a/man/config.Rd +++ b/man/config.Rd @@ -40,7 +40,7 @@ for an \strong{rmarkdown} example and Set the default configuration for plotly } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # remove the plotly logo and collaborate button from modebar config(plot_ly(), displaylogo = FALSE, collaborate = FALSE) diff --git a/man/group2NA.Rd b/man/group2NA.Rd index ac2ffb658f..539c353bbb 100644 --- a/man/group2NA.Rd +++ b/man/group2NA.Rd @@ -45,7 +45,7 @@ In this case, one should also take care to make sure is set to \code{FALSE}. } \examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive()) withAutoprint(\{ # examplesIf} # note the insertion of new rows with missing values group2NA(mtcars, "vs", "cyl") diff --git a/man/hide_colorbar.Rd b/man/hide_colorbar.Rd index 39432261ff..5d4b94c780 100644 --- a/man/hide_colorbar.Rd +++ b/man/hide_colorbar.Rd @@ -13,7 +13,7 @@ hide_colorbar(p) Hide color bar(s) } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} p <- plot_ly(mtcars, x = ~wt, y = ~cyl, color = ~cyl) hide_colorbar(p) diff --git a/man/hide_legend.Rd b/man/hide_legend.Rd index 62b3fe6169..82ab7d4292 100644 --- a/man/hide_legend.Rd +++ b/man/hide_legend.Rd @@ -13,7 +13,7 @@ hide_legend(p) Hide legend } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} p <- plot_ly(mtcars, x = ~wt, y = ~cyl, color = ~factor(cyl)) hide_legend(p) diff --git a/man/highlight.Rd b/man/highlight.Rd index 35f36f9807..7589bda081 100644 --- a/man/highlight.Rd +++ b/man/highlight.Rd @@ -84,7 +84,7 @@ other htmlwidgets will respect these options, such as persistent selection in leaflet (see \code{demo("highlight-leaflet", package = "plotly")}). } \examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive()) withAutoprint(\{ # examplesIf} # These examples are designed to show you how to highlight/brush a *single* # view. For examples of multiple linked views, see `demo(package = "plotly")` diff --git a/man/last_plot.Rd b/man/last_plot.Rd index 640b044ed3..24a0a7d5a8 100644 --- a/man/last_plot.Rd +++ b/man/last_plot.Rd @@ -10,5 +10,5 @@ last_plot() Retrieve the last plot to be modified or created. } \seealso{ -\code{\link[ggplot2:last_plot]{ggplot2::last_plot()}} +\code{\link[ggplot2:get_last_plot]{ggplot2::last_plot()}} } diff --git a/man/orca.Rd b/man/orca.Rd index efd96093d2..3cee80ec0a 100644 --- a/man/orca.Rd +++ b/man/orca.Rd @@ -107,7 +107,7 @@ The \code{orca_serve()} function returns an object with two fields: } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ # NOTE: in a headless environment, you may need to set `more_args="--enable-webgl"` diff --git a/man/partial_bundle.Rd b/man/partial_bundle.Rd index 1dd56819c9..43eb5f852e 100644 --- a/man/partial_bundle.Rd +++ b/man/partial_bundle.Rd @@ -31,7 +31,7 @@ bundles are used, the most recent bundle will override the other bundles. See the examples section for an example. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # ---------------------------------------------------------------------- # This function is always safe to use when rendering a single diff --git a/man/plot_dendro.Rd b/man/plot_dendro.Rd index 2bcee03240..fc537ebfa4 100644 --- a/man/plot_dendro.Rd +++ b/man/plot_dendro.Rd @@ -25,7 +25,7 @@ interactive dendrogram. Selecting a node selects all the labels (i.e. leafs) under that node. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ hc <- hclust(dist(USArrests), "ave") diff --git a/man/plot_geo.Rd b/man/plot_geo.Rd index b62cfa754b..eb475e98b8 100644 --- a/man/plot_geo.Rd +++ b/man/plot_geo.Rd @@ -22,7 +22,7 @@ the scattergeo trace type, and enables higher level geometries like \code{\link[=add_polygons]{add_polygons()}} to work } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} map_data("world", "canada") \%>\% group_by(group) \%>\% diff --git a/man/plot_ly.Rd b/man/plot_ly.Rd index b32d197483..688471853c 100644 --- a/man/plot_ly.Rd +++ b/man/plot_ly.Rd @@ -133,7 +133,7 @@ help inform default axis/scale titles (e.g., \code{plot_ly(x = mtcars$wt)} vs \code{plot_ly(x = ~mtcars$wt)}) } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ # plot_ly() tries to create a sensible plot based on the information you diff --git a/man/plotlyProxy.Rd b/man/plotlyProxy.Rd index ce3317ac24..054bb40b6a 100644 --- a/man/plotlyProxy.Rd +++ b/man/plotlyProxy.Rd @@ -36,7 +36,7 @@ visit \url{https://plotly.com/javascript/plotlyjs-function-reference/}} Modify a plotly object inside a shiny app } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} if (require("shiny") && interactive()) { diff --git a/man/plotly_build.Rd b/man/plotly_build.Rd index 01bd27da18..f9f877c92a 100644 --- a/man/plotly_build.Rd +++ b/man/plotly_build.Rd @@ -18,7 +18,7 @@ provided by \code{ggplotly}/\code{plot_ly} or for debugging rendering errors. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} p <- plot_ly(economics, x = ~date, y = ~pce) # the unevaluated plotly object diff --git a/man/plotly_data.Rd b/man/plotly_data.Rd index dca16810f8..039b64b125 100644 --- a/man/plotly_data.Rd +++ b/man/plotly_data.Rd @@ -95,7 +95,7 @@ a plotly visualization (if there are multiple data frames, by default, it returns the most recent one). } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # use group_by() to define groups of visual markings p <- txhousing \%>\% diff --git a/man/plotly_json.Rd b/man/plotly_json.Rd index 76031c7fe8..729efd1dc1 100644 --- a/man/plotly_json.Rd +++ b/man/plotly_json.Rd @@ -21,7 +21,7 @@ This function is useful for obtaining/viewing/debugging JSON sent to plotly.js. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} plotly_json(plot_ly()) plotly_json(plot_ly(), FALSE) diff --git a/man/rangeslider.Rd b/man/rangeslider.Rd index 870554ac80..1d35b0a1ab 100644 --- a/man/rangeslider.Rd +++ b/man/rangeslider.Rd @@ -20,7 +20,7 @@ rangeslider(p, start = NULL, end = NULL, ...) Add a range slider to the x-axis } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} plot_ly(x = time(USAccDeaths), y = USAccDeaths) \%>\% add_lines() \%>\% diff --git a/man/raster2uri.Rd b/man/raster2uri.Rd index fb8e7f6180..e8d372d207 100644 --- a/man/raster2uri.Rd +++ b/man/raster2uri.Rd @@ -18,7 +18,7 @@ This is especially convenient for embedding raster images on a plot in a self-contained fashion (i.e., so they don't depend on external URL links). } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # a red gradient (from ?as.raster) r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5)) diff --git a/man/remove_typedarray_polyfill.Rd b/man/remove_typedarray_polyfill.Rd index 82d3e77c88..1d37f5ffa7 100644 --- a/man/remove_typedarray_polyfill.Rd +++ b/man/remove_typedarray_polyfill.Rd @@ -19,7 +19,7 @@ The polyfill seems to be only relevant for those rendering plots via phantomjs and RStudio on some Windows platforms. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ p1 <- plot_ly() diff --git a/man/save_image.Rd b/man/save_image.Rd index baebd94f09..8b249c1efc 100644 --- a/man/save_image.Rd +++ b/man/save_image.Rd @@ -57,7 +57,7 @@ py_install(c("kaleido", "plotly")) } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} \dontrun{ # Save a single image diff --git a/man/schema.Rd b/man/schema.Rd index ae8e9cbef2..c959aeaa93 100644 --- a/man/schema.Rd +++ b/man/schema.Rd @@ -16,7 +16,7 @@ The schema contains valid attributes names, their value type, default values (if any), and min/max values (if applicable). } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} s <- schema() # retrieve acceptable `layout.mapbox.style` values diff --git a/man/showRGB.Rd b/man/showRGB.Rd index 6cfe8f07d2..c28b20a8ff 100644 --- a/man/showRGB.Rd +++ b/man/showRGB.Rd @@ -16,7 +16,7 @@ Useful for viewing colors after they've been converted to plotly.js' color format -- "rgba(255, 255, 255, 1)" } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} showRGB(toRGB(colors()), labels = FALSE) \dontshow{\}) # examplesIf} diff --git a/man/style.Rd b/man/style.Rd index aff55e6b47..761afefc90 100644 --- a/man/style.Rd +++ b/man/style.Rd @@ -19,7 +19,7 @@ Modify trace(s) of an existing plotly visualization. Useful when used in conjunction with \code{\link[=get_figure]{get_figure()}}. } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # style() is especially useful in conjunction with ggplotly() # It allows you to leverage the underlying plotly.js library to change diff --git a/man/subplot.Rd b/man/subplot.Rd index d093109f62..ee1d120109 100644 --- a/man/subplot.Rd +++ b/man/subplot.Rd @@ -60,7 +60,7 @@ A plotly object View multiple plots in a single view } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # pass any number of plotly objects to subplot() p1 <- plot_ly(economics, x = ~date, y = ~uempmed) diff --git a/man/toRGB.Rd b/man/toRGB.Rd index 210c48ec59..6cd4f862fe 100644 --- a/man/toRGB.Rd +++ b/man/toRGB.Rd @@ -18,7 +18,7 @@ hexadecimal colour value (if is.na(x), return "transparent" for compatibility wi Convert R colours to RGBA hexadecimal colour values } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} toRGB("steelblue") # [1] "rgba(70,130,180,1)" diff --git a/man/toWebGL.Rd b/man/toWebGL.Rd index 09bf27dfd5..6f7f851e63 100644 --- a/man/toWebGL.Rd +++ b/man/toWebGL.Rd @@ -13,7 +13,7 @@ toWebGL(p) Convert trace types to WebGL } \examples{ -\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # currently no bargl trace type toWebGL(ggplot() + geom_bar(aes(1:10))) diff --git a/tests/testthat/_snaps/ggplot-contour/contour.svg b/tests/testthat/_snaps/ggplot-contour/contour.svg index b4c92209c7..47086596a9 100644 --- a/tests/testthat/_snaps/ggplot-contour/contour.svg +++ b/tests/testthat/_snaps/ggplot-contour/contour.svg @@ -1 +1 @@ -02550750204060xy +02550750204060xy diff --git a/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg b/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg index 8faa71dc34..c9fea70072 100644 --- a/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg +++ b/tests/testthat/_snaps/ggplot-legend/guide-aes-none.svg @@ -1 +1 @@ -Jan 02Jan 04Jan 06Jan 08Jan 10-2-1012colourMeanQCSeriesASeriesBDateMean +Jan 02Jan 04Jan 06Jan 08Jan 10-2-1012SeriesMeanQCSeriesASeriesBDateMean diff --git a/tests/testthat/helper-skip.R b/tests/testthat/helper-skip.R index 6a953bd3ab..1414b9e828 100644 --- a/tests/testthat/helper-skip.R +++ b/tests/testthat/helper-skip.R @@ -18,7 +18,7 @@ skip_cloud_tests <- function() { skip_shinytest_tests <- function() { skip_on_cran() - skip_if_not_installed("shinytest") + skip_if_not_installed("shinytest2") if (!grepl("true", Sys.getenv("SHINYTEST"), fixed = TRUE)) { skip("shinytest testing requires the SHINYTEST environment variable to be true") } diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R index e84b90f5a1..1c70c85e5a 100644 --- a/tests/testthat/test-api.R +++ b/tests/testthat/test-api.R @@ -1,3 +1,5 @@ +skip("plotly seems to no longer support the 'Chart Studio' API https://plotly.com/chart-studio-updates/") + test_that("api() returns endpoints", { skip_cloud_tests() @@ -207,5 +209,3 @@ test_that("posting a hidden plot returns a secret key", { expect_true(res$share_key_enabled) expect_true(nchar(res$share_key) > 1) }) - -