Skip to content

Commit 665504a

Browse files
authored
Fixes for the development version of ggplot2 (> v3.5.2); migrate to shinytest2 (#2359)
* Use new complete_theme() function to get the complete set of theme elements * Refactor and reuse logic in tests * Fix kaleido install * Accept good snapshot changes * Disable windows oldrel * Close #2357. In some cases, decor has min/max instead of value. In that case, treat max like value * Accept new historgram binning changes * Make sure layout-specific shapes go underneath traces * Accept new snapshots; migrate to shinytest2 * Check-in snapshots
1 parent ed106db commit 665504a

File tree

87 files changed

+167
-134
lines changed

Some content is hidden

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

87 files changed

+167
-134
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ jobs:
2929
# vdiffr & shinytest only runs on mac r-release since the results aren't cross-platform
3030
- {os: macOS-latest, r: 'release', visual_tests: true, node: "14.x", shinytest: true}
3131
- {os: windows-latest, r: 'release'}
32-
- {os: windows-latest, r: '4.1'}
33-
- {os: windows-latest, r: '3.6'}
32+
# - {os: windows-latest, r: 'oldrel-1'} # pak is having issues
3433
- {os: ubuntu-latest, r: 'devel'}
3534
- {os: ubuntu-latest, r: 'release'}
3635
- {os: ubuntu-latest, r: 'oldrel-1'}
@@ -62,26 +61,10 @@ jobs:
6261
cache-version: 3
6362
needs: check
6463

65-
- name: Set up Python 3.8
66-
uses: actions/setup-python@v2
67-
with:
68-
python-version: 3.8
69-
7064
- name: Install kaleido
7165
if: matrix.config.visual_tests == true
7266
run: |
73-
sudo chown -R $UID $CONDA # https://github.com/nextstrain/conda/issues/5
74-
Rscript -e "reticulate::install_miniconda()"
75-
Rscript -e "reticulate::conda_install('r-reticulate', 'python-kaleido')"
76-
Rscript -e "reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')"
77-
Rscript -e "reticulate::use_miniconda('r-reticulate')"
78-
79-
- name: Install shinytest deps
80-
if: matrix.config.shinytest == true
81-
run: |
82-
Rscript -e 'shinytest::installDependencies()'
83-
R CMD install .
84-
shell: bash
67+
Rscript -e 'library(reticulate); use_python(install_python()); py_install(c("kaleido", "plotly"))'
8568
8669
# Run test() before R CMD check since, for some reason, rcmdcheck::rcmdcheck() skips vdiffr tests
8770
- name: Run Tests

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Suggests:
5757
testthat,
5858
knitr,
5959
shiny (>= 1.1.0),
60-
shinytest (>= 1.3.0),
60+
shinytest2,
6161
curl,
6262
rmarkdown,
6363
Cairo,

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
* `ggplotly()` now supports the `{ggridges}` package. (#2314)
66

7+
## Improvements
8+
9+
* `ggplotly()` now works better with the development version of ggplot2 (> v3.4.4). (#2315)
10+
711
## Bug fixes
812

913
* Closed #2337: Creating a new `event_data()` handler no longer causes a spurious reactive update of existing `event_data()`s. (#2339)

R/ggplotly.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,8 @@ gg2list <- function(p, width = NULL, height = NULL,
463463
assign(var, built_env[[var]], envir = envir)
464464
}
465465

466-
# initiate plotly.js layout with some plot-wide theming stuff
467-
theme <- ggfun("plot_theme")(plot)
468-
elements <- names(which(sapply(theme, inherits, "element")))
469-
for (i in elements) {
470-
theme[[i]] <- ggplot2::calc_element(i, theme)
471-
}
466+
theme <- calculated_theme_elements(plot)
467+
472468
# Translate plot wide theme elements to plotly.js layout
473469
pm <- unitConvert(theme$plot.margin, "pixels")
474470
gglayout <- list(
@@ -1154,6 +1150,23 @@ gg2list <- function(p, width = NULL, height = NULL,
11541150
# Due to the non-standard use of assign() in g2list() (above)
11551151
utils::globalVariables(c("groupDomains", "layers", "prestats_data", "scales", "sets"))
11561152

1153+
# Get the "complete" set of theme elements and their calculated values
1154+
calculated_theme_elements <- function(plot) {
1155+
if (is.function(asNamespace("ggplot2")$complete_theme)) {
1156+
theme <- ggplot2::complete_theme(plot$theme)
1157+
elements <- names(theme)
1158+
} else {
1159+
theme <- ggfun("plot_theme")(plot)
1160+
elements <- names(which(sapply(theme, inherits, "element")))
1161+
}
1162+
1163+
for (i in elements) {
1164+
theme[[i]] <- ggplot2::calc_element(i, theme)
1165+
}
1166+
1167+
theme
1168+
}
1169+
11571170

11581171
#-----------------------------------------------------------------------------
11591172
# ggplotly 'utility' functions
@@ -1384,7 +1397,8 @@ rect2shape <- function(rekt = ggplot2::element_rect()) {
13841397
linetype = lty2dash(rekt$linetype)
13851398
),
13861399
yref = "paper",
1387-
xref = "paper"
1400+
xref = "paper",
1401+
layer = "below"
13881402
)
13891403
}
13901404

@@ -1408,6 +1422,7 @@ gdef2trace <- function(gdef, theme, gglayout) {
14081422
# N.B. ggplot2 >v3.4.2 (specifically #4879) renamed bar to decor and also
14091423
# started returning normalized values for the key field
14101424
decor <- gdef$decor %||% gdef$bar
1425+
decor$value <- decor$value %||% decor$max
14111426
rng <- range(decor$value)
14121427
decor$value <- scales::rescale(decor$value, from = rng)
14131428
if (!"decor" %in% names(gdef)) {
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

inst/examples/shiny/event_data/tests/shinytest/mytest.R

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shinytest2::test_app()

0 commit comments

Comments
 (0)