Skip to content

Commit

Permalink
Merge branch 'master' into gen-plotly-bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-b committed Sep 4, 2024
2 parents 93ef777 + 0454f38 commit 666075b
Show file tree
Hide file tree
Showing 116 changed files with 933 additions and 176 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
# vdiffr & shinytest only runs on mac r-release since the results aren't cross-platform
- {os: macOS-latest, r: 'release', visual_tests: true, node: "14.x", shinytest: true}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: '4.1'}
- {os: windows-latest, r: '3.6'}
# - {os: windows-latest, r: 'oldrel-1'} # pak is having issues
- {os: ubuntu-latest, r: 'devel'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
Expand All @@ -48,6 +47,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
persist-credentials: false

- uses: r-lib/actions/setup-r@v2
id: install-r
Expand All @@ -62,26 +63,10 @@ jobs:
cache-version: 3
needs: check

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install kaleido
if: matrix.config.visual_tests == true
run: |
sudo chown -R $UID $CONDA # https://github.com/nextstrain/conda/issues/5
Rscript -e "reticulate::install_miniconda()"
Rscript -e "reticulate::conda_install('r-reticulate', 'python-kaleido')"
Rscript -e "reticulate::conda_install('r-reticulate', 'plotly', channel = 'plotly')"
Rscript -e "reticulate::use_miniconda('r-reticulate')"
- name: Install shinytest deps
if: matrix.config.shinytest == true
run: |
Rscript -e 'shinytest::installDependencies()'
R CMD install .
shell: bash
Rscript -e 'library(reticulate); use_python(install_python()); py_install(c("kaleido", "plotly"))'
# Run test() before R CMD check since, for some reason, rcmdcheck::rcmdcheck() skips vdiffr tests
- name: Run Tests
Expand All @@ -98,7 +83,9 @@ jobs:
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: ./
path: |
./
!./.git/
- name: Check package
uses: r-lib/actions/check-r-package@v2
Expand Down
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Imports:
vctrs,
tibble,
lazyeval (>= 0.2.0),
rlang (>= 0.4.10),
rlang (>= 1.0.0),
crosstalk,
purrr,
data.table,
Expand All @@ -57,7 +57,7 @@ Suggests:
testthat,
knitr,
shiny (>= 1.1.0),
shinytest (>= 1.3.0),
shinytest2,
curl,
rmarkdown,
Cairo,
Expand All @@ -75,7 +75,8 @@ Suggests:
palmerpenguins,
rversions,
reticulate,
rsvg
rsvg,
ggridges
LazyData: true
RoxygenNote: 7.3.1
Encoding: UTF-8
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ S3method(geom2trace,GeomErrorbarh)
S3method(geom2trace,GeomPath)
S3method(geom2trace,GeomPoint)
S3method(geom2trace,GeomPolygon)
S3method(geom2trace,GeomRidgelineGradient)
S3method(geom2trace,GeomText)
S3method(geom2trace,GeomTile)
S3method(geom2trace,default)
Expand Down Expand Up @@ -49,6 +50,10 @@ S3method(to_basic,GeomContour)
S3method(to_basic,GeomCrossbar)
S3method(to_basic,GeomDensity)
S3method(to_basic,GeomDensity2d)
S3method(to_basic,GeomDensityLine)
S3method(to_basic,GeomDensityRidges)
S3method(to_basic,GeomDensityRidges2)
S3method(to_basic,GeomDensityRidgesGradient)
S3method(to_basic,GeomDotplot)
S3method(to_basic,GeomErrorbar)
S3method(to_basic,GeomErrorbarh)
Expand All @@ -65,6 +70,8 @@ S3method(to_basic,GeomRaster)
S3method(to_basic,GeomRasterAnn)
S3method(to_basic,GeomRect)
S3method(to_basic,GeomRibbon)
S3method(to_basic,GeomRidgeline)
S3method(to_basic,GeomRidgelineGradient)
S3method(to_basic,GeomRug)
S3method(to_basic,GeomSegment)
S3method(to_basic,GeomSf)
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# plotly (development version)

## New features

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

## Improvements

* `ggplotly()` now works better with the development version of ggplot2 (> v3.4.4). (#2315, #2368)

## Bug fixes

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

# 4.10.4

## Improvements
Expand Down
4 changes: 2 additions & 2 deletions R/export.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Export a plotly graph to a static file
#'
#' This function is in the process of being deprecated (use [orca] instead).
#' This function is deprecated, use [save_image] instead.
#'
#' @details For SVG plots, a screenshot is taken via `webshot::webshot()`.
#' Since `phantomjs` (and hence `webshot`) does not support WebGL,
Expand All @@ -19,7 +19,7 @@
#' @author Carson Sievert
#'
export <- function(p = last_plot(), file = "plotly.png", selenium = NULL, ...) {
.Deprecated("orca")
.Deprecated("save_image")

# infer the file type
fileType <- tolower(tools::file_ext(file))
Expand Down
34 changes: 27 additions & 7 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ gg2list <- function(p, width = NULL, height = NULL,

# Compute aesthetics to produce data with generalised variable names
data <- by_layer(function(l, d) l$compute_aesthetics(d, plot))
if (exists("setup_plot_labels", envir = asNamespace("ggplot2"))) {
# Mirror ggplot2/#5879
plot$labels <- ggfun("setup_plot_labels")(plot, layers, data)
}


# add frame to group if it exists
data <- lapply(data, function(d) {
Expand Down Expand Up @@ -463,12 +468,8 @@ gg2list <- function(p, width = NULL, height = NULL,
assign(var, built_env[[var]], envir = envir)
}

# initiate plotly.js layout with some plot-wide theming stuff
theme <- ggfun("plot_theme")(plot)
elements <- names(which(sapply(theme, inherits, "element")))
for (i in elements) {
theme[[i]] <- ggplot2::calc_element(i, theme)
}
theme <- calculated_theme_elements(plot)

# Translate plot wide theme elements to plotly.js layout
pm <- unitConvert(theme$plot.margin, "pixels")
gglayout <- list(
Expand Down Expand Up @@ -1154,6 +1155,23 @@ gg2list <- function(p, width = NULL, height = NULL,
# Due to the non-standard use of assign() in g2list() (above)
utils::globalVariables(c("groupDomains", "layers", "prestats_data", "scales", "sets"))

# Get the "complete" set of theme elements and their calculated values
calculated_theme_elements <- function(plot) {
if (is.function(asNamespace("ggplot2")$complete_theme)) {
theme <- ggplot2::complete_theme(plot$theme)
elements <- names(theme)
} else {
theme <- ggfun("plot_theme")(plot)
elements <- names(which(sapply(theme, inherits, "element")))
}

for (i in elements) {
theme[[i]] <- ggplot2::calc_element(i, theme)
}

theme
}


#-----------------------------------------------------------------------------
# ggplotly 'utility' functions
Expand Down Expand Up @@ -1384,7 +1402,8 @@ rect2shape <- function(rekt = ggplot2::element_rect()) {
linetype = lty2dash(rekt$linetype)
),
yref = "paper",
xref = "paper"
xref = "paper",
layer = "below"
)
}

Expand All @@ -1408,6 +1427,7 @@ gdef2trace <- function(gdef, theme, gglayout) {
# N.B. ggplot2 >v3.4.2 (specifically #4879) renamed bar to decor and also
# started returning normalized values for the key field
decor <- gdef$decor %||% gdef$bar
decor$value <- decor$value %||% decor$max
rng <- range(decor$value)
decor$value <- scales::rescale(decor$value, from = rng)
if (!"decor" %in% names(gdef)) {
Expand Down
Loading

0 comments on commit 666075b

Please sign in to comment.