diff --git a/R/plotly_build.R b/R/plotly_build.R index 2cf5de65aa..abaa8e5b61 100644 --- a/R/plotly_build.R +++ b/R/plotly_build.R @@ -280,10 +280,12 @@ plotly_build.plotly <- function(p, registerFrames = TRUE) { ) for (i in x$.plotlyVariableMapping) { # try to reduce the amount of data we have to send for non-positional scales - x[[i]] <- structure( - if (i %in% npscales()) uniq(d[[i]]) else d[[i]], - class = oldClass(x[[i]]) - ) + entry <- if (i %in% npscales()) uniq(d[[i]]) else d[[i]] + if (is.null(entry)) { + x[[i]] <- NULL + } else { + x[[i]] <- structure(entry, class = oldClass(x[[i]])) + } } x }) diff --git a/tests/testthat/test-ggplot-lines.R b/tests/testthat/test-ggplot-lines.R index 08095c8694..e0d437985a 100644 --- a/tests/testthat/test-ggplot-lines.R +++ b/tests/testthat/test-ggplot-lines.R @@ -120,3 +120,10 @@ test_that("geom_linerange() without a y aesthetic translates to a path", { ) }) + +test_that("NA values do not cause a lot of warnings when ploting (#1299)", { + df <- data.frame(x=1:2, y=NA) + p <- plot_ly(df, x=~x, y=~y) + expect_warning(plotly_build(p), "Ignoring") + expect_failure(expect_warning(plotly_build(p), "structure")) +})