Skip to content

[pull] master from ropensci:master #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ rsconnect/
revdep/
travis_debug.R
.httr-oauth
tests/testthat/Rplots.pdf
inst/examples/shiny/event_data/tests/shinytest/mytest-current/
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ Imports:
viridisLite,
base64enc,
htmltools (>= 0.3.6),
htmlwidgets (>= 1.3),
htmlwidgets (>= 1.5.2.9001),
tidyr,
hexbin,
RColorBrewer,
dplyr,
vctrs,
Expand All @@ -51,6 +50,7 @@ Imports:
Suggests:
MASS,
maps,
hexbin,
ggthemes,
GGally,
testthat,
Expand All @@ -74,7 +74,8 @@ Suggests:
processx,
plotlyGeoAssets,
forcats,
thematic
thematic,
palmerpenguins
LazyData: true
RoxygenNote: 7.1.1
Encoding: UTF-8
Expand Down
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

## Changes to plotly.js

* 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.
* 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.

## NEW FEATURES

* `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).
* `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).

* `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).

## IMPROVEMENTS

Expand All @@ -16,12 +18,16 @@

## BUG FIXES

* 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).

* `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).

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

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

* `ggplotly()` now handles missing `y` aesthetic in `geom_errorbar()` (#1779, @trekonom).

# 4.9.2.1

This is minor patch release with a few minor bug fixes and updates test expectations in anticipation of new R 4.0 defaults.
Expand Down
17 changes: 11 additions & 6 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
#' @seealso [plot_ly()]
#' @examples \dontrun{
#' # simple example
#' ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
#' ggplotly(ggiris)
#' ggpenguins <- qplot(bill_length_mm , body_mass_g,
#' data = palmerpenguins::penguins, color = species)
#' ggplotly(ggpenguins)
#'
#' data(canada.cities, package = "maps")
#' viz <- ggplot(canada.cities, aes(long, lat)) +
Expand All @@ -58,7 +59,7 @@
#' demo("crosstalk-highlight-ggplotly", package = "plotly")
#'
#' # client-side linked brushing in a scatterplot matrix
#' highlight_key(iris) %>%
#' highlight_key(palmerpenguins::penguins) %>%
#' GGally::ggpairs(aes(colour = Species), columns = 1:4) %>%
#' ggplotly(tooltip = c("x", "y", "colour")) %>%
#' highlight("plotly_selected")
Expand Down Expand Up @@ -175,12 +176,12 @@ gg2list <- function(p, width = NULL, height = NULL,

# To convert relative sizes correctly, we use grid::convertHeight(),
# which requires a known output (device) size.
dev_fun <- if (system.file(package = "Cairo") != "") {
Cairo::Cairo
} else if (capabilities("png")) {
dev_fun <- if (capabilities("aqua") || capabilities("png")) {
grDevices::png
} else if (capabilities("jpeg")) {
grDevices::jpeg
} else if (system.file(package = "Cairo") != "") {
Cairo::Cairo
} else {
stop(
"No Cairo or bitmap device is available. Such a graphics device is required to convert sizes correctly in ggplotly().\n\n",
Expand Down Expand Up @@ -1131,6 +1132,10 @@ 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"))


#-----------------------------------------------------------------------------
# ggplotly 'utility' functions
#-----------------------------------------------------------------------------
Expand Down
20 changes: 18 additions & 2 deletions R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ to_basic.GeomErrorbar <- function(data, prestats_data, layout, params, p, ...) {
# width for ggplot2 means size of the entire bar, on the data scale
# (plotly.js wants half, in pixels)
data <- merge(data, layout$layout, by = "PANEL", sort = FALSE)
data$width <- (data[["xmax"]] - data[["x"]]) /(data[["x_max"]] - data[["x_min"]])
data$width <- if (params[["flipped_aes"]]) {
(data[["ymax"]] - data[["y"]]) /(data[["y_max"]] - data[["y_min"]])
} else {
(data[["xmax"]] - data[["x"]]) /(data[["x_max"]] - data[["x_min"]])
}
data$fill <- NULL
prefix_class(data, "GeomErrorbar")
}
Expand Down Expand Up @@ -873,7 +877,17 @@ geom2trace.GeomTile <- function(data, params, p) {

#' @export
geom2trace.GeomErrorbar <- function(data, params, p) {
make_error(data, params, "y")
# Support of bi-directional GeomErrorbar introduced with ggplot2 3.3.0
# g <- ggplot() + geom_errorbar(aes(y = "A", xmin = 1, xmax = 2))
# ggplotly(g)
# Support of bi-directional GeomErrorbar introduced with ggplot2 3.3.0:
# g <- ggplot() + geom_errorbar(aes(y = "A", xmin = 1, xmax = 2))
# ggplotly(g)
if (params[["flipped_aes"]]) {
make_error(data, params, "x")
} else {
make_error(data, params, "y")
}
}

#' @export
Expand Down Expand Up @@ -951,6 +965,8 @@ hover_on <- function(data) {

# make trace with errorbars
make_error <- function(data, params, xy = "x") {
# if xy is NULL: set xy to mean of xy_min and xy_max
data[[xy]] <- data[[xy]] %||% ((data[[paste0(xy, "min")]] + data[[paste0(xy, "max")]]) / 2)
color <- aes2plotly(data, params, "colour")
e <- list(
x = data[["x"]],
Expand Down
14 changes: 7 additions & 7 deletions R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@
#' # You might notice plot_ly() has named arguments that aren't in this figure
#' # reference. These arguments make it easier to map abstract data values to
#' # visual attributes.
#' p <- plot_ly(iris, x = ~Sepal.Width, y = ~Sepal.Length)
#' add_markers(p, color = ~Petal.Length, size = ~Petal.Length)
#' add_markers(p, color = ~Species)
#' add_markers(p, color = ~Species, colors = "Set1")
#' add_markers(p, symbol = ~Species)
#' add_paths(p, linetype = ~Species)
#' p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~body_mass_g)
#' add_markers(p, color = ~bill_depth_mm, size = ~bill_depth_mm)
#' add_markers(p, color = ~species)
#' add_markers(p, color = ~species, colors = "Set1")
#' add_markers(p, symbol = ~species)
#' add_paths(p, linetype = ~species)
#'
#' }
#'
Expand Down Expand Up @@ -479,7 +479,7 @@ typedArrayPolyfill <- function() {
plotlyMainBundle <- function() {
htmltools::htmlDependency(
name = "plotly-main",
version = "1.54.1",
version = "1.57.1",
package = "plotly",
src = dependency_dir("plotlyjs"),
script = "plotly-latest.min.js",
Expand Down
9 changes: 5 additions & 4 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ plotlyOutput <- function(outputId, width = "100%", height = "400px",
package = "plotly",
reportSize = TRUE
)
if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.1.9001")) {
if (is_available("shiny", "1.4.0.9003") && is_available("htmlwidgets", "1.5.2.9000")) {
args$reportTheme <- reportTheme
}
do.call(htmlwidgets::shinyWidgetOutput, args)
Expand All @@ -55,9 +55,10 @@ renderPlotly <- function(expr, env = parent.frame(), quoted = FALSE) {
# objects to renderPlotly() (e.g., ggplot2, promises). It also is used
# to inform event_data about what events have been registered
shiny::installExprFunction(expr, "func", env, quoted)
expr <- quote(getFromNamespace("prepareWidget", "plotly")(func()))
local_env <- environment()
renderFunc <- shinyRenderWidget(expr, plotlyOutput, local_env, quoted)
expr2 <- quote(getFromNamespace("prepareWidget", "plotly")(func()))
renderFunc <- shinyRenderWidget(expr2, plotlyOutput, environment(), quoted,
cacheHint = list(label = "renderPlotly", userExpr = expr)
)
# remove 'internal' plotly attributes that are known to cause false
# positive test results in shinytest (snapshotPreprocessOutput was added
# in shiny 1.0.3.9002, but we require >= 1.1)
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ try_file <- function(f, what) {
# preferred defaults for toJSON mapping
to_JSON <- function(x, ...) {
jsonlite::toJSON(x, digits = 50, auto_unbox = TRUE, force = TRUE,
null = "null", na = "null", ...)
null = "null", na = "null",
time_format = "%Y-%m-%d %H:%M:%OS6", ...)
}

# preferred defaults for toJSON mapping
Expand Down
21 changes: 8 additions & 13 deletions inst/docker/Dockerfile.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,16 @@ RUN R -e "update.packages(ask = F); invisible(lapply(list('devtools', 'roxygen2'
RUN add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes \
&& apt-get -y update \
&& apt-get install -y libudunits2-dev libproj-dev libgeos-dev libgdal-dev

# ragg dependencies
RUN apt-get install -y libharfbuzz-dev libfribidi-dev

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

# system dependencies related to running orca
RUN apt-get install -y \
libgtk2.0-0 \
libgconf-2-4 \
xvfb \
xauth \
libxtst6 \
libxss1 \
libnss3 \
libasound2 \
desktop-file-utils
RUN apt-get -y update \
&& apt-get install -y libgtk2.0-0 libgconf-2-4 xvfb xauth libxtst6 libxss1 libnss3 libasound2 desktop-file-utils

# google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
Expand All @@ -88,16 +83,16 @@ RUN mkdir -p /opt/orca \
ENV VDIFFR=true
EXPOSE 3838


ARG CRANCACHE=1
RUN R -e "update.packages(ask=FALSE)"
RUN R -e "remotes::install_github('r-lib/vdiffr')"

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

CMD cd /home/plotly; R -e "if (!identical(Sys.getenv('VMODE'), 'ci')) vdiffr::manage_cases(); \
CMD cd /home/plotly; R -e "remotes::install_deps(dependencies = T); \
if (!identical(Sys.getenv('VMODE'), 'ci')) vdiffr::manage_cases(); \
res <- devtools::test(reporter='summary'); \
df <- as.data.frame(res); \
if (sum(df\$failed) > 0 || any(df\$error)) q(status=1)"
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-htmlwidgets-css-1.54.1"
"href": "plotly-htmlwidgets-css-1.57.1"
},
"meta": null,
"script": null,
Expand All @@ -452,9 +452,9 @@
},
{
"name": "plotly-main",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-main-1.54.1"
"href": "plotly-main-1.57.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-htmlwidgets-css-1.54.1"
"href": "plotly-htmlwidgets-css-1.57.1"
},
"meta": null,
"script": null,
Expand All @@ -469,9 +469,9 @@
},
{
"name": "plotly-main",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-main-1.54.1"
"href": "plotly-main-1.57.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-htmlwidgets-css-1.54.1"
"href": "plotly-htmlwidgets-css-1.57.1"
},
"meta": null,
"script": null,
Expand All @@ -473,9 +473,9 @@
},
{
"name": "plotly-main",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-main-1.54.1"
"href": "plotly-main-1.57.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@
},
{
"name": "plotly-htmlwidgets-css",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-htmlwidgets-css-1.54.1"
"href": "plotly-htmlwidgets-css-1.57.1"
},
"meta": null,
"script": null,
Expand All @@ -474,9 +474,9 @@
},
{
"name": "plotly-main",
"version": "1.54.1",
"version": "1.57.1",
"src": {
"href": "plotly-main-1.54.1"
"href": "plotly-main-1.57.1"
},
"meta": null,
"script": "plotly-latest.min.js",
Expand Down
20 changes: 10 additions & 10 deletions inst/htmlwidgets/lib/plotlyjs/plotly-latest.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions man/ggplotly.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading