diff --git a/R/utils.R b/R/utils.R index cc3395d4ac..5175bdc941 100644 --- a/R/utils.R +++ b/R/utils.R @@ -823,14 +823,15 @@ verify_webgl <- function(p) { return(p) } types <- sapply(p$x$data, function(x) x[["type"]][1] %||% "scatter") - idx <- paste0(types, "gl") %in% names(Schema$traces) - if (any(!idx)) { + can_gl <- paste0(types, "gl") %in% names(Schema$traces) + already_gl <- grepl("gl$", types) + if (any(!can_gl & !already_gl)) { warning( "The following traces don't have a WebGL equivalent: ", - paste(which(!idx), collapse = ", ") + paste(which(!can_gl & !already_gl), collapse = ", ") ) } - for (i in which(idx)) { + for (i in which(can_gl)) { p$x$data[[i]]$type <- paste0(p$x$data[[i]]$type, "gl") } p diff --git a/tests/testthat/test-plotly.R b/tests/testthat/test-plotly.R index 0e84bd8232..8dd43a405a 100644 --- a/tests/testthat/test-plotly.R +++ b/tests/testthat/test-plotly.R @@ -310,3 +310,10 @@ test_that("Informative deprecation message for titlefont", { p <- layout(plot_ly(), title = "A title", titlefont = list(size = 30)) expect_warning(plotly_build(p), "titlefont") }) + +test_that("toWebGL() shouldn't complain if it's already webgl", { + p <- plot_ly(x = 1, y = 1) %>% + add_trace(type = "scattergl", mode = "markers") %>% + toWebGL() + expect_silent(plotly_build(p)) +})