Skip to content

Commit e2afc47

Browse files
authored
Upgrade to plotly.js 2.0 (#1967)
* wip upgrade to plotly.js 2.0 * patch plotly.js source to support phantomjs/shinytest reverts part of plotly/plotly.js#5380 * bump mathjax version * use npm instead of yarn * make geom_bar() default to textposition='none'; approve new vdiffr 0.4 + plotly.js 2.0 baselines * Migrate to vdiffr 1.0 * Use layout.legend.title over layout.annotations to when converting guides for discrete scales * wip migrate to gha * try npm install * setup node * use recommended node version * try mac instead * install phantomjs; various cleanup * intentionally break a visual test * fix * use thematic's approach to testing * bump version * regenerate snapshots * map secrets to env variables * accept new gha baselines * whoops * hmm * approve shinytest baseline * intentionally break a visual test * always upload * revert change; new baselines * Remove the vdiffr dependency and use testthat snaphots directly * More obvious env var naming * more gha details * always upload * new snaps * intentionally break a visual test (again) * Revert "intentionally break a visual test (again)" This reverts commit a4e306c.
1 parent 6f3e1f8 commit e2afc47

File tree

765 files changed

+864
-868
lines changed

Some content is hidden

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

765 files changed

+864
-868
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ revdep/
2020
README.Rmd
2121
abbvie.R
2222
^\.httr-oauth$
23+
^\.github$

.github/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/R-CMD-check.yaml

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# NOTE: This workflow is overkill for most R packages
2+
# check-standard.yaml is likely a better choice
3+
# usethis::use_github_action("check-standard") will install it.
4+
#
5+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
6+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
7+
on:
8+
push:
9+
branches:
10+
- main
11+
- master
12+
pull_request:
13+
branches:
14+
- main
15+
- master
16+
17+
name: R-CMD-check
18+
19+
jobs:
20+
R-CMD-check:
21+
runs-on: ${{ matrix.config.os }}
22+
23+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
config:
29+
- {os: macOS-latest, r: 'release', visual_tests: true, node: "14.x", shinytest: true}
30+
- {os: windows-latest, r: 'release'}
31+
- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"}
32+
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.1.0 (ubuntu-18.04) R (4.1.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
33+
# vdiffr & shinytest only runs on linux r-release since the results aren't cross-platform
34+
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
35+
- {os: ubuntu-18.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
36+
- {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
37+
- {os: ubuntu-18.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
38+
- {os: ubuntu-18.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
39+
40+
env:
41+
RSPM: ${{ matrix.config.rspm }}
42+
VISUAL_TESTS: ${{ matrix.config.visual_tests }}
43+
SHINYTEST: ${{ matrix.config.shinytest }}
44+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
45+
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
46+
plotly_username: ${{ secrets.PLOTLY_USERNAME }}
47+
plotly_api_key: ${{ secrets.PLOTLY_API_KEY }}
48+
49+
steps:
50+
- uses: actions/checkout@v2
51+
52+
- uses: r-lib/actions/setup-r@v1
53+
id: install-r
54+
with:
55+
r-version: ${{ matrix.config.r }}
56+
http-user-agent: ${{ matrix.config.http-user-agent }}
57+
58+
- uses: r-lib/actions/setup-pandoc@v1
59+
60+
- name: Install pak and query dependencies
61+
run: |
62+
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
63+
saveRDS(pak::pkg_deps("local::.", dependencies = TRUE), ".github/r-depends.rds")
64+
shell: Rscript {0}
65+
66+
- name: Restore R package cache
67+
uses: actions/cache@v2
68+
with:
69+
path: |
70+
${{ env.R_LIBS_USER }}/*
71+
!${{ env.R_LIBS_USER }}/pak
72+
key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }}
73+
restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-
74+
75+
- name: Install system dependencies
76+
if: runner.os == 'Linux'
77+
run: |
78+
pak::local_system_requirements(execute = TRUE)
79+
pak::pkg_system_requirements("rcmdcheck", execute = TRUE)
80+
shell: Rscript {0}
81+
82+
- uses: actions/setup-node@v1
83+
with:
84+
node-version: ${{ matrix.config.node }}
85+
86+
- name: Install orca
87+
if: matrix.config.visual_tests == true
88+
run: npm install -g [email protected] orca
89+
shell: bash
90+
91+
- name: Install phantomjs
92+
if: matrix.config.shinytest == true
93+
run: |
94+
pak::pak("shinytest")
95+
shinytest::installDependencies()
96+
pak::pak()
97+
shell: Rscript {0}
98+
99+
- name: Install dependencies
100+
run: |
101+
pak::local_install_dev_deps(upgrade = TRUE)
102+
pak::pkg_install("rcmdcheck")
103+
shell: Rscript {0}
104+
105+
- name: Session info
106+
run: |
107+
options(width = 100)
108+
pkgs <- installed.packages()[, "Package"]
109+
sessioninfo::session_info(pkgs, include_base = TRUE)
110+
shell: Rscript {0}
111+
112+
# Run test() before R CMD check since, for some reason, rcmdcheck::rcmdcheck() skips vdiffr tests
113+
- name: Run Tests
114+
run: |
115+
options(crayon.enabled = TRUE)
116+
if (!require(devtools)) pak::pak("devtools")
117+
if (!require(reshape2)) pak::pak("reshape2")
118+
res <- devtools::test()
119+
df <- as.data.frame(res)
120+
if (sum(df$failed) > 0 || any(df$error)) stop("GHA CI tests failed")
121+
shell: Rscript {0}
122+
123+
# Upload the whole pkg since tests where run with devtools::test()
124+
- name: Upload check results
125+
if: always()
126+
uses: actions/upload-artifact@master
127+
with:
128+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
129+
path: ./
130+
131+
# Run check with --no-tests since we ran them abve
132+
- name: Check
133+
run: |
134+
options(crayon.enabled = TRUE)
135+
rcmdcheck::rcmdcheck(args = c("--no-tests", "--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
136+
shell: Rscript {0}
137+
138+
#- name: Show testthat output
139+
# if: always()
140+
# run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
141+
# shell: bash
142+
143+
- name: Don't use tar from old Rtools to store the cache
144+
if: ${{ runner.os == 'Windows' && startsWith(steps.install-r.outputs.installed-r-version, '3.6' ) }}
145+
shell: bash
146+
run: echo "C:/Program Files/Git/usr/bin" >> $GITHUB_PATH

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ revdep/
1818
travis_debug.R
1919
.httr-oauth
2020
tests/testthat/Rplots.pdf
21-
inst/examples/shiny/event_data/tests/shinytest/mytest-current/

.travis.yml

-36
This file was deleted.

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Suggests:
6060
shinytest (>= 1.3.0),
6161
curl,
6262
rmarkdown,
63-
vdiffr,
6463
Cairo,
6564
broom,
6665
webshot,
@@ -74,7 +73,8 @@ Suggests:
7473
processx,
7574
plotlyGeoAssets,
7675
forcats,
77-
palmerpenguins
76+
palmerpenguins,
77+
rversions
7878
LazyData: true
7979
RoxygenNote: 7.1.1
8080
Encoding: UTF-8

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# 4.9.4.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.57.1 to v2.0.0. This includes many breaking changes, bug fixes, and improvements to the underlying JavaScript library. The [plotly.js release page](https://github.com/plotly/plotly.js/releases) has the full list of changes.
6+
7+
## Breaking changes
8+
9+
* `ggplotly()` now uses the `layout.legend.title` (instead of `layout.annotations`) plotly.js API to convert guides for discrete scales. (#1961)
310

411
# 4.9.4.1
512

R/ggplotly.R

+6-20
Original file line numberDiff line numberDiff line change
@@ -999,26 +999,12 @@ gg2list <- function(p, width = NULL, height = NULL,
999999
}
10001000
traces <- c(traces, colorbar)
10011001

1002-
# legend title annotation - https://github.com/plotly/plotly.js/issues/276
1003-
if (isTRUE(gglayout$showlegend)) {
1004-
legendTitles <- compact(lapply(gdefs, function(g) if (inherits(g, "legend")) g$title else NULL))
1005-
legendTitle <- paste(legendTitles, collapse = br())
1006-
titleAnnotation <- make_label(
1007-
legendTitle,
1008-
x = gglayout$legend$x %||% 1.02,
1009-
y = gglayout$legend$y %||% 1,
1010-
theme$legend.title,
1011-
xanchor = "left",
1012-
yanchor = "bottom",
1013-
# just so the R client knows this is a title
1014-
legendTitle = TRUE
1015-
)
1016-
gglayout$annotations <- c(gglayout$annotations, titleAnnotation)
1017-
# adjust the height of the legend to accomodate for the title
1018-
# this assumes the legend always appears below colorbars
1019-
gglayout$legend$y <- (gglayout$legend$y %||% 1) -
1020-
length(legendTitles) * unitConvert(theme$legend.title$size, "npc", "height")
1021-
}
1002+
legendTitles <- compact(lapply(gdefs, function(g) if (inherits(g, "legend")) g$title else NULL))
1003+
legendTitle <- paste(legendTitles, collapse = br())
1004+
gglayout$legend$title <- list(
1005+
text = legendTitle,
1006+
font = text2font(theme$legend.title)
1007+
)
10221008
}
10231009

10241010
# flip x/y in traces for flipped coordinates

R/layers2traces.R

+5
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ geom2trace.GeomBar <- function(data, params, p) {
736736
frame = data[["frame"]],
737737
ids = data[["ids"]],
738738
type = "bar",
739+
# plotly.js v2.0 changed default to textposition='auto', meaning
740+
# text will display by default, which makes sense for plot_ly() maybe,
741+
# but not ggplotly()
742+
# https://github.com/plotly/orca/issues/374
743+
textposition = "none",
739744
marker = list(
740745
autocolorscale = FALSE,
741746
color = toRGB(

R/mathjax.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ is.TeX <- function(x) {
2828
mathjax_cdn <- function() {
2929
htmltools::htmlDependency(
3030
name = "mathjax",
31-
version = "2.7.4",
31+
version = "2.7.5",
3232
package = "plotly",
3333
src = dependency_dir("mathjax"),
3434
script = "cdn.js"

R/plotly.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ typedArrayPolyfill <- function() {
479479
plotlyMainBundle <- function() {
480480
htmltools::htmlDependency(
481481
name = "plotly-main",
482-
version = "1.57.1",
482+
version = "2.0.0",
483483
package = "plotly",
484484
src = dependency_dir("plotlyjs"),
485485
script = "plotly-latest.min.js",

R/sysdata.rda

2.2 KB
Binary file not shown.

R/utils.R

-3
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,6 @@ verify_showlegend <- function(p) {
845845
# this attribute should be set in hide_legend()
846846
# it ensures that "legend titles" go away in addition to showlegend = FALSE
847847
if (isTRUE(p$x$.hideLegend)) {
848-
ann <- p$x$layout$annotations
849-
is_title <- vapply(ann, function(x) isTRUE(x$legendTitle), logical(1))
850-
p$x$layout$annotations <- ann[!is_title]
851848
p$x$layout$showlegend <- FALSE
852849
}
853850
show <- vapply(p$x$data, function(x) x$showlegend %||% TRUE, logical(1))

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
<img src="man/figures/plotly.png" width="200" />
55

6-
[![Build
7-
Status](https://travis-ci.org/ropensci/plotly.png?branch=master)](https://travis-ci.org/ropensci/plotly)
6+
<!-- badges: start -->
7+
[![R-CMD-check](https://github.com/ropensci/plotly/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/plotly/actions)
88
[![CRAN
99
Status](https://www.r-pkg.org/badges/version/plotly)](https://cran.r-project.org/package=plotly)
1010
[![CRAN
1111
Downloads](https://cranlogs.r-pkg.org/badges/grand-total/plotly)](https://www.rpackages.io/package/plotly)
1212
[![monthly](https://cranlogs.r-pkg.org/badges/plotly)](https://www.rpackages.io/package/plotly)
13+
<!-- badges: end -->
1314

1415
An R package for creating interactive web graphics via the open source
1516
JavaScript graphing library
@@ -23,10 +24,10 @@ Install from CRAN:
2324
install.packages("plotly")
2425
```
2526

26-
Or install the latest development version (on GitHub) via devtools:
27+
Or install the latest development version (on GitHub) via `{remotes}`:
2728

2829
``` r
29-
devtools::install_github("ropensci/plotly")
30+
remotes::install_github("ropensci/plotly")
3031
```
3132

3233
## Getting started

0 commit comments

Comments
 (0)