Skip to content

Commit b6cb77b

Browse files
committed
Merge pull #8
Merge branch 'ropensci-master' # Conflicts: # R/plotly.R # inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js
2 parents 894f509 + 94011cb commit b6cb77b

File tree

196 files changed

+465
-313
lines changed

Some content is hidden

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

196 files changed

+465
-313
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ rsconnect/
1717
revdep/
1818
travis_debug.R
1919
.httr-oauth
20+
tests/testthat/Rplots.pdf
21+
inst/examples/shiny/event_data/tests/shinytest/mytest-current/

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ Imports:
3535
viridisLite,
3636
base64enc,
3737
htmltools (>= 0.3.6),
38-
htmlwidgets (>= 1.3),
38+
htmlwidgets (>= 1.5.2.9001),
3939
tidyr,
40-
hexbin,
4140
RColorBrewer,
4241
dplyr,
4342
vctrs,
@@ -51,6 +50,7 @@ Imports:
5150
Suggests:
5251
MASS,
5352
maps,
53+
hexbin,
5454
ggthemes,
5555
GGally,
5656
testthat,
@@ -74,7 +74,8 @@ Suggests:
7474
processx,
7575
plotlyGeoAssets,
7676
forcats,
77-
thematic
77+
thematic,
78+
palmerpenguins
7879
LazyData: true
7980
RoxygenNote: 7.1.1
8081
Encoding: UTF-8

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ This is minor patch release with a few minor bug fixes and updates test expectat
4040

4141
## Changes to plotly.js
4242

43-
* 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.
43+
* This version of the R package upgrades the version of the underlying plotly.js library from v1.52.2 to v1.57.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.
4444

4545
## NEW FEATURES
4646

47-
* `ggplotly()` now works well with the [**thematic** package](https://rstudio.github.io/thematic). That is, it can now correctly translate **ggplot2** styling that derives from **thematic**. Note that, in order to use **thematic**'s auto theming in Shiny with `ggplotly()`, you need **shiny** v1.5.0 (or higher) and **htmlwidgets** v1.5.1.9001 (or higher). Relatedly, if these versions are available, one may now also call `getCurrentOutputInfo()` inside `renderPlotly()` to get CSS styles of the output container (#1801 and #1802).
47+
* `renderPlotly()` now works well with `shiny::bindCache()`, meaning that plotly graphs can now be persistently cached in Shiny apps with `renderPlotly(expr) %>% shiny::bindCache()` (#1879).
48+
49+
* `ggplotly()` now works well with the [**thematic** package](https://rstudio.github.io/thematic). That is, it can now correctly translate **ggplot2** styling that derives from **thematic**. Note that, in order to use **thematic**'s auto theming in Shiny with `ggplotly()`, you need **shiny** v1.5.0 (or higher) and **htmlwidgets** v1.5.2.9000 (or higher). Relatedly, if these versions are available, one may now also call `getCurrentOutputInfo()` inside `renderPlotly()` to get CSS styles of the output container (#1801 and #1802).
4850

4951
## IMPROVEMENTS
5052

@@ -56,12 +58,16 @@ This is minor patch release with a few minor bug fixes and updates test expectat
5658

5759
## BUG FIXES
5860

61+
* When R's `POSIXt` class is serialized to JSON, the time of day is now correctly preserved (in plotly.js expected `'yyyy-mm-dd HH:MM:SS.ssssss'` format). This should fix a whole host of issues where date-times were being rounded. (#1871, @FlukeAndFeather).
62+
5963
* `ggplotly()` now handles discrete axes of a `facet_wrap` and `facet_grid` correctly when there is only one category in panels > 1 (#1577 and #1720).
6064

6165
* `ggplotly()` now correctly accounts for linebreaks in tick label text when computing plot margins (#1791, @trekonom).
6266

6367
* `ggplotly()` now handles `element_blank()` and `factor()` labels in positional scales correctly (#1731 and #1772).
6468

69+
* `ggplotly()` now handles missing `y` aesthetic in `geom_errorbar()` (#1779, @trekonom).
70+
6571
# 4.9.2.1
6672

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

R/ggplotly.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
#' @seealso [plot_ly()]
3737
#' @examples \dontrun{
3838
#' # simple example
39-
#' ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
40-
#' ggplotly(ggiris)
39+
#' ggpenguins <- qplot(bill_length_mm , body_mass_g,
40+
#' data = palmerpenguins::penguins, color = species)
41+
#' ggplotly(ggpenguins)
4142
#'
4243
#' data(canada.cities, package = "maps")
4344
#' viz <- ggplot(canada.cities, aes(long, lat)) +
@@ -58,7 +59,7 @@
5859
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
5960
#'
6061
#' # client-side linked brushing in a scatterplot matrix
61-
#' highlight_key(iris) %>%
62+
#' highlight_key(palmerpenguins::penguins) %>%
6263
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
6364
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
6465
#' highlight("plotly_selected")
@@ -175,12 +176,12 @@ gg2list <- function(p, width = NULL, height = NULL,
175176

176177
# To convert relative sizes correctly, we use grid::convertHeight(),
177178
# which requires a known output (device) size.
178-
dev_fun <- if (system.file(package = "Cairo") != "") {
179-
Cairo::Cairo
180-
} else if (capabilities("png")) {
179+
dev_fun <- if (capabilities("aqua") || capabilities("png")) {
181180
grDevices::png
182181
} else if (capabilities("jpeg")) {
183182
grDevices::jpeg
183+
} else if (system.file(package = "Cairo") != "") {
184+
Cairo::Cairo
184185
} else {
185186
stop(
186187
"No Cairo or bitmap device is available. Such a graphics device is required to convert sizes correctly in ggplotly().\n\n",
@@ -1131,6 +1132,10 @@ gg2list <- function(p, width = NULL, height = NULL,
11311132
}
11321133

11331134

1135+
# Due to the non-standard use of assign() in g2list() (above)
1136+
utils::globalVariables(c("groupDomains", "layers", "prestats_data", "scales", "sets"))
1137+
1138+
11341139
#-----------------------------------------------------------------------------
11351140
# ggplotly 'utility' functions
11361141
#-----------------------------------------------------------------------------

R/layers2traces.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,11 @@ to_basic.GeomErrorbar <- function(data, prestats_data, layout, params, p, ...) {
451451
# width for ggplot2 means size of the entire bar, on the data scale
452452
# (plotly.js wants half, in pixels)
453453
data <- merge(data, layout$layout, by = "PANEL", sort = FALSE)
454-
data$width <- (data[["xmax"]] - data[["x"]]) /(data[["x_max"]] - data[["x_min"]])
454+
data$width <- if (params[["flipped_aes"]]) {
455+
(data[["ymax"]] - data[["y"]]) /(data[["y_max"]] - data[["y_min"]])
456+
} else {
457+
(data[["xmax"]] - data[["x"]]) /(data[["x_max"]] - data[["x_min"]])
458+
}
455459
data$fill <- NULL
456460
prefix_class(data, "GeomErrorbar")
457461
}
@@ -873,7 +877,17 @@ geom2trace.GeomTile <- function(data, params, p) {
873877

874878
#' @export
875879
geom2trace.GeomErrorbar <- function(data, params, p) {
876-
make_error(data, params, "y")
880+
# Support of bi-directional GeomErrorbar introduced with ggplot2 3.3.0
881+
# g <- ggplot() + geom_errorbar(aes(y = "A", xmin = 1, xmax = 2))
882+
# ggplotly(g)
883+
# Support of bi-directional GeomErrorbar introduced with ggplot2 3.3.0:
884+
# g <- ggplot() + geom_errorbar(aes(y = "A", xmin = 1, xmax = 2))
885+
# ggplotly(g)
886+
if (params[["flipped_aes"]]) {
887+
make_error(data, params, "x")
888+
} else {
889+
make_error(data, params, "y")
890+
}
877891
}
878892

879893
#' @export
@@ -951,6 +965,8 @@ hover_on <- function(data) {
951965

952966
# make trace with errorbars
953967
make_error <- function(data, params, xy = "x") {
968+
# if xy is NULL: set xy to mean of xy_min and xy_max
969+
data[[xy]] <- data[[xy]] %||% ((data[[paste0(xy, "min")]] + data[[paste0(xy, "max")]]) / 2)
954970
color <- aes2plotly(data, params, "colour")
955971
e <- list(
956972
x = data[["x"]],

R/plotly.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
#' # You might notice plot_ly() has named arguments that aren't in this figure
119119
#' # reference. These arguments make it easier to map abstract data values to
120120
#' # visual attributes.
121-
#' p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length)
122-
#' add_markers(p, color = ~Petal.Length, size = ~Petal.Length)
123-
#' add_markers(p, color = ~Species)
124-
#' add_markers(p, color = ~Species, colors = "Set1")
125-
#' add_markers(p, symbol = ~Species)
126-
#' add_paths(p, linetype = ~Species)
121+
#' p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~body_mass_g)
122+
#' add_markers(p, color = ~bill_depth_mm, size = ~bill_depth_mm)
123+
#' add_markers(p, color = ~species)
124+
#' add_markers(p, color = ~species, colors = "Set1")
125+
#' add_markers(p, symbol = ~species)
126+
#' add_paths(p, linetype = ~species)
127127
#'
128128
#' }
129129
#'
@@ -479,7 +479,7 @@ typedArrayPolyfill <- function() {
479479
plotlyMainBundle <- function() {
480480
htmltools::htmlDependency(
481481
name = "plotly-main",
482-
version = "1.58.0",
482+
version = "1.57.1",
483483
package = "plotly",
484484
src = dependency_dir("plotlyjs"),
485485
script = "plotly-latest.min.js",

R/shiny.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px",
3434
package = "plotly",
3535
reportSize = TRUE
3636
)
37-
if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.1.9001")) {
37+
if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.2.9000")) {
3838
args$reportTheme <- reportTheme
3939
}
4040
do.call(htmlwidgets::shinyWidgetOutput, args)
@@ -55,9 +55,10 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
5555
# objects to renderPlotly() (e.g., ggplot2, promises). It also is used
5656
# to inform event_data about what events have been registered
5757
shiny::installExprFunction(expr, "func", env, quoted)
58-
expr <- quote(getFromNamespace("prepareWidget", "plotly")(func()))
59-
local_env <- environment()
60-
renderFunc <- shinyRenderWidget(expr, plotlyOutput, local_env, quoted)
58+
expr2 <- quote(getFromNamespace("prepareWidget", "plotly")(func()))
59+
renderFunc <- shinyRenderWidget(expr2, plotlyOutput, environment(), quoted,
60+
cacheHint = list(label = "renderPlotly", userExpr = expr)
61+
)
6162
# remove 'internal' plotly attributes that are known to cause false
6263
# positive test results in shinytest (snapshotPreprocessOutput was added
6364
# in shiny 1.0.3.9002, but we require >= 1.1)

R/utils.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,8 @@ try_file <- function(f, what) {
10211021
# preferred defaults for toJSON mapping
10221022
to_JSON <- function(x, ...) {
10231023
jsonlite::toJSON(x, digits = 50, auto_unbox = TRUE, force = TRUE,
1024-
null = "null", na = "null", ...)
1024+
null = "null", na = "null",
1025+
time_format = "%Y-%m-%d %H:%M:%OS6", ...)
10251026
}
10261027

10271028
# preferred defaults for toJSON mapping

inst/docker/Dockerfile.vtest

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,16 @@ RUN R -e "update.packages(ask = F); invisible(lapply(list('devtools', 'roxygen2'
5252
RUN add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes \
5353
&& apt-get -y update \
5454
&& apt-get install -y libudunits2-dev libproj-dev libgeos-dev libgdal-dev
55+
56+
# ragg dependencies
57+
RUN apt-get install -y libharfbuzz-dev libfribidi-dev
5558

5659
# Install all plotly's dependencies
5760
RUN R -e "install.packages('plotly', dependencies = T)"
5861

5962
# system dependencies related to running orca
60-
RUN apt-get install -y \
61-
libgtk2.0-0 \
62-
libgconf-2-4 \
63-
xvfb \
64-
xauth \
65-
libxtst6 \
66-
libxss1 \
67-
libnss3 \
68-
libasound2 \
69-
desktop-file-utils
63+
RUN apt-get -y update \
64+
&& apt-get install -y libgtk2.0-0 libgconf-2-4 xvfb xauth libxtst6 libxss1 libnss3 libasound2 desktop-file-utils
7065

7166
# google chrome
7267
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
@@ -88,15 +83,19 @@ RUN mkdir -p /opt/orca \
8883
ENV VDIFFR=true
8984
EXPOSE 3838
9085

86+
<<<<<<< HEAD
87+
=======
88+
ARG CRANCACHE=1
89+
>>>>>>> e7419594a7e6a424ab6bbb1c9e26f44877146cf1
9190
RUN R -e "update.packages(ask=FALSE)"
9291
RUN R -e "remotes::install_github('r-lib/vdiffr')"
9392

9493
# install any new dependencies, then either manage cases (the default) or run tests
9594
# note the workaround to get docker to run a proper exit status when there are testthat errors
9695
# https://github.com/r-lib/testthat/issues/515#issuecomment-304169376
97-
CMD R -e "remotes::install_deps(dep = TRUE)"
9896

99-
CMD cd /home/plotly; R -e "if (!identical(Sys.getenv('VMODE'), 'ci')) vdiffr::manage_cases(); \
97+
CMD cd /home/plotly; R -e "remotes::install_deps(dependencies = T); \
98+
if (!identical(Sys.getenv('VMODE'), 'ci')) vdiffr::manage_cases(); \
10099
res <- devtools::test(reporter='summary'); \
101100
df <- as.data.frame(res); \
102101
if (sum(df\$failed) > 0 || any(df\$error)) q(status=1)"

inst/examples/shiny/event_data/tests/shinytest/mytest-expected/001.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@
439439
},
440440
{
441441
"name": "plotly-htmlwidgets-css",
442-
"version": "1.54.1",
442+
"version": "1.57.1",
443443
"src": {
444-
"href": "plotly-htmlwidgets-css-1.54.1"
444+
"href": "plotly-htmlwidgets-css-1.57.1"
445445
},
446446
"meta": null,
447447
"script": null,
@@ -452,9 +452,9 @@
452452
},
453453
{
454454
"name": "plotly-main",
455-
"version": "1.54.1",
455+
"version": "1.57.1",
456456
"src": {
457-
"href": "plotly-main-1.54.1"
457+
"href": "plotly-main-1.57.1"
458458
},
459459
"meta": null,
460460
"script": "plotly-latest.min.js",

0 commit comments

Comments
 (0)