diff --git a/R/ggplotly.R b/R/ggplotly.R index e3d2097e64..6e0c2d9009 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -236,10 +236,18 @@ gg2list <- function(p, width = NULL, height = NULL, out } + # ggplot2 3.1.0.9000 introduced a Layer method named setup_layer() + # currently, LayerSf is the only core-ggplot2 Layer that makes use + # of it https://github.com/tidyverse/ggplot2/pull/2875 + data <- layer_data + if (packageVersion("ggplot2") > "3.1.0") { + data <- by_layer(function(l, d) l$setup_layer(d, plot)) + } + # Initialise panels, add extra data for margins & missing facetting # variables, and add on a PANEL variable to data layout <- ggfun("create_layout")(plot$facet, plot$coordinates) - data <- layout$setup(layer_data, plot$data, plot$plot_env) + data <- layout$setup(data, plot$data, plot$plot_env) # save the domain of the group for display in tooltips groupDomains <- Map(function(x, y) { diff --git a/R/layers2traces.R b/R/layers2traces.R index 563b8174cf..fba34f75c9 100644 --- a/R/layers2traces.R +++ b/R/layers2traces.R @@ -1000,7 +1000,12 @@ aes2plotly <- function(data, params, aes = "size") { type <- if (any(grepl("point", class(data)))) "point" else if (any(grepl("line", class(data)))) "line" else "" ggfun("default_aesthetics")(type) } else { - ggfun(geom)$default_aes + geom_obj <- ggfun(geom) + # If the first class of `data` is a data.frame, + # ggfun() returns a function because ggplot2 now + # defines data.frame in it's namespace + # https://github.com/ropensci/plotly/pull/1481 + if ("default_aes" %in% names(geom_obj)) geom_obj$default_aes else NULL } vals <- uniq(data[[aes]]) %||% params[[aes]] %||% defaults[[aes]] %||% NA