Skip to content

Commit 9abcba9

Browse files
remove frameOrder warning (#1927)
* remove frameOrder warning * use expect_warning * fix bunch of tests warnings * update expected shinytest (jquery and crosstalk versions) * Apply suggestions from code review Co-authored-by: Carson Sievert <[email protected]> Co-authored-by: Carson Sievert <[email protected]>
1 parent 8201019 commit 9abcba9

22 files changed

+142
-69
lines changed

R/plotly_build.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ registerFrames <- function(p, frameMapping = NULL) {
425425
# remove frames from the trace names
426426
for (i in seq_along(p$x$data)) {
427427
tr <- p$x$data[[i]]
428-
if (length(tr[["name"]]) != 1) next
428+
if (length(tr[["name"]]) != 1) {
429+
p$x$data[[i]]$frameOrder <- NULL
430+
next
431+
}
429432
nms <- strsplit(as.character(tr[["name"]]), br())[[1]]
430433
idx <- setdiff(seq_along(nms), tr$frameOrder %||% 0)
431434
p$x$data[[i]]$name <- if (length(idx)) paste(nms[idx], collapse = br()) else NULL

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@
413413
},
414414
{
415415
"name": "jquery",
416-
"version": "1.11.3",
416+
"version": "3.5.1",
417417
"src": {
418-
"href": "jquery-1.11.3"
418+
"href": "jquery-3.5.1"
419419
},
420420
"meta": null,
421421
"script": "jquery.min.js",
@@ -426,9 +426,9 @@
426426
},
427427
{
428428
"name": "crosstalk",
429-
"version": "1.1.0.1",
429+
"version": "1.1.1",
430430
"src": {
431-
"href": "crosstalk-1.1.0.1"
431+
"href": "crosstalk-1.1.1"
432432
},
433433
"meta": null,
434434
"script": "js/crosstalk.min.js",
Loading

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@
430430
},
431431
{
432432
"name": "jquery",
433-
"version": "1.11.3",
433+
"version": "3.5.1",
434434
"src": {
435-
"href": "jquery-1.11.3"
435+
"href": "jquery-3.5.1"
436436
},
437437
"meta": null,
438438
"script": "jquery.min.js",
@@ -443,9 +443,9 @@
443443
},
444444
{
445445
"name": "crosstalk",
446-
"version": "1.1.0.1",
446+
"version": "1.1.1",
447447
"src": {
448-
"href": "crosstalk-1.1.0.1"
448+
"href": "crosstalk-1.1.1"
449449
},
450450
"meta": null,
451451
"script": "js/crosstalk.min.js",
Loading

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@
434434
},
435435
{
436436
"name": "jquery",
437-
"version": "1.11.3",
437+
"version": "3.5.1",
438438
"src": {
439-
"href": "jquery-1.11.3"
439+
"href": "jquery-3.5.1"
440440
},
441441
"meta": null,
442442
"script": "jquery.min.js",
@@ -447,9 +447,9 @@
447447
},
448448
{
449449
"name": "crosstalk",
450-
"version": "1.1.0.1",
450+
"version": "1.1.1",
451451
"src": {
452-
"href": "crosstalk-1.1.0.1"
452+
"href": "crosstalk-1.1.1"
453453
},
454454
"meta": null,
455455
"script": "js/crosstalk.min.js",
Loading

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,9 @@
435435
},
436436
{
437437
"name": "jquery",
438-
"version": "1.11.3",
438+
"version": "3.5.1",
439439
"src": {
440-
"href": "jquery-1.11.3"
440+
"href": "jquery-3.5.1"
441441
},
442442
"meta": null,
443443
"script": "jquery.min.js",
@@ -448,9 +448,9 @@
448448
},
449449
{
450450
"name": "crosstalk",
451-
"version": "1.1.0.1",
451+
"version": "1.1.1",
452452
"src": {
453-
"href": "crosstalk-1.1.0.1"
453+
"href": "crosstalk-1.1.1"
454454
},
455455
"meta": null,
456456
"script": "js/crosstalk.min.js",
Loading

tests/testthat/test-animate-highlight.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ test_that("simple animation targeting works", {
359359

360360
test_that("animation frames are boxed up correctly", {
361361
dallas <- subset(txhousing, city == "Dallas" & month == 1)
362-
p <- ggplot(dallas) +
363-
geom_point(aes(x = volume, y = sales, frame = year))
362+
p <- ggplot(dallas, aes(x = volume, y = sales, frame = year)) +
363+
geom_point()
364364
l <- plotly_build(p)$x
365365

366366
for (i in seq_along(l$frames)) {

tests/testthat/test-cookbook-axes.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ test_that("factor levels determine tick order", {
3333
## range are dropped, resulting in a misleading box plot.
3434
bp.ylim.hide <- bp + ylim(5, 7.5)
3535
test_that("ylim hides points", {
36-
info <- expect_traces(bp.ylim.hide, 1, "ylim.hide")
36+
info <- expect_warning(expect_traces(bp.ylim.hide, 1, "ylim.hide"),
37+
regexp = "non-finite values")
3738
})
3839

3940
bp.scale.hide <- bp + scale_y_continuous(limits = c(5, 7.5))
4041
test_that("scale_y(limits) hides points", {
41-
info <- expect_traces(bp.scale.hide, 1, "scale.hide")
42+
info <- expect_warning(expect_traces(bp.scale.hide, 1, "scale.hide"),
43+
regexp = "non-finite values")
4244
expect_equivalent(range(info$layout$yaxis$tickvals), c(5, 7.5))
4345
y <- unlist(lapply(info$data, "[[", "y"))
4446
expect_true(all(5 <= y & y <= 7.5, na.rm = TRUE))

tests/testthat/test-ggplot-date.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ test_that("scale_x_date and irregular time series work", {
3333
)
3434
df <- df[order(df$date), ]
3535
dt <- qplot(date, price, data = df, geom = "line") + theme(aspect.ratio = 1/4)
36-
info <- expect_doppelganger_built(dt, "date-irregular-time-series")
36+
37+
info <- expect_warning(expect_doppelganger_built(dt, "date-irregular-time-series"),
38+
regexp = "Aspect ratios aren't yet implemented")
3739
})

tests/testthat/test-ggplot-dynamicTicks.R

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ test_that("Categorical axis reflects custom scale mapping", {
3333
g <- ggplot(mpg, aes(class, color = class)) +
3434
geom_bar() +
3535
scale_x_discrete(limits = lims)
36-
p <- ggplotly(g, dynamicTicks = "x")
36+
37+
expect_warning(p <- ggplotly(g, dynamicTicks = "x"),
38+
regexp = "non-finite values")
3739

3840
axisActual <- with(
3941
p$x$layout$xaxis, list(type, tickmode, categoryorder, categoryarray)
@@ -48,7 +50,8 @@ test_that("Categorical axis reflects custom scale mapping", {
4850
g <- ggplot(mpg, aes(class, color = class)) +
4951
geom_bar() +
5052
scale_x_discrete(limits = lims, labels = labs)
51-
p <- ggplotly(g, dynamicTicks = "x")
53+
expect_warning(p <- ggplotly(g, dynamicTicks = "x"),
54+
regexp = "non-finite values")
5255

5356
axisActual <- with(
5457
p$x$layout$xaxis, list(type, tickmode, categoryorder, categoryarray)
@@ -103,4 +106,3 @@ test_that("Inverse maps colorbar data", {
103106
expect_true(l$data[[2]]$y %in% unique(mpg$manufacturer))
104107

105108
})
106-

tests/testthat/test-ggplot-ticks.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ test_that('boxes with coord_flip()+facet_grid(scales="free")', {
5656

5757
test_that("limits can hide data", {
5858
boxes.limits <- boxes + scale_x_discrete(limits = c("trt1", "ctrl"))
59-
info <- expect_traces(boxes.limits, 1, "limits-hide")
59+
info <- expect_warning(expect_traces(boxes.limits, 1, "limits-hide"),
60+
regexp = "missing values")
6061
expect_equivalent(info$layout$xaxis$ticktext, c("trt1", "ctrl"))
6162
})
6263

tests/testthat/test-plotly-color.R

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,31 @@ test_that("plot_ly() handles a simple scatterplot", {
1212
})
1313

1414
test_that("Mapping a factor variable to color works", {
15-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species)
15+
d <- palmerpenguins::penguins %>%
16+
filter(!is.na(bill_length_mm))
17+
p <- plot_ly(d, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species)
1618
l <- expect_traces(p, 3, "scatterplot-color-factor")
1719
markers <- lapply(l$data, "[[", "marker")
1820
cols <- unlist(lapply(markers, "[[", "color"))
1921
expect_equivalent(length(cols), 3)
2022
})
2123

2224
test_that("Custom RColorBrewer pallette works for factor variable", {
25+
d <- palmerpenguins::penguins %>%
26+
filter(!is.na(bill_length_mm))
2327
cols <- RColorBrewer::brewer.pal(9, "Set1")
2428
# convert hex to rgba spec for comparison's sake
2529
colsToCompare <- toRGB(cols)
2630
# specifying a pallette set should "span the gamut"
27-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species,
31+
p <- plot_ly(d, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species,
2832
colors = "Set1")
2933
l <- expect_traces(p, 3, "scatterplot-color-factor-custom")
3034
markers <- lapply(l$data, "[[", "marker")
3135
colz <- unlist(lapply(markers, "[[", "color"))
3236
idx <- if (packageVersion("scales") > '1.0.0') c(1, 2, 3) else c(1, 5, 9)
3337
expect_identical(sort(colsToCompare[idx]), sort(colz))
3438
# providing vector of RGB codes should also work
35-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species,
39+
p <- plot_ly(d, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~species,
3640
colors = cols[1:3])
3741
l <- expect_traces(p, 3, "scatterplot-color-factor-custom2")
3842
markers <- lapply(l$data, "[[", "marker")
@@ -51,7 +55,9 @@ test_that("Passing hex codes to colors argument works", {
5155
})
5256

5357
test_that("Mapping a numeric variable to color works", {
54-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~bill_depth_mm)
58+
d <- palmerpenguins::penguins %>%
59+
filter(!is.na(bill_length_mm))
60+
p <- plot_ly(d, x = ~bill_length_mm, y = ~flipper_length_mm, color = ~bill_depth_mm)
5561
# one trace is for the colorbar
5662
l <- expect_traces(p, 2, "scatterplot-color-numeric")
5763
idx <- vapply(l$data, is.colorbar, logical(1))
@@ -76,14 +82,18 @@ test_that("color/stroke mapping with box translates correctly", {
7682
})
7783

7884
test_that("Custom RColorBrewer pallette works for numeric variable", {
79-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~flipper_length_mm,
85+
d <- palmerpenguins::penguins %>%
86+
filter(!is.na(bill_length_mm))
87+
p <- plot_ly(d, x = ~bill_length_mm, y = ~flipper_length_mm,
8088
color = ~bill_depth_mm, colors = "Greens")
8189
# one trace is for the colorbar
8290
l <- expect_traces(p, 2, "scatterplot-color-numeric-custom")
8391
})
8492

8593
test_that("axis titles get attached to scene object for 3D plots", {
86-
p <- plot_ly(palmerpenguins::penguins, x = ~bill_length_mm, y = ~bill_depth_mm, z = ~flipper_length_mm)
94+
d <- palmerpenguins::penguins %>%
95+
filter(!is.na(bill_length_mm))
96+
p <- plot_ly(d, x = ~bill_length_mm, y = ~bill_depth_mm, z = ~flipper_length_mm)
8797
l <- expect_traces(p, 1, "scatterplot-scatter3d-axes")
8898
expect_identical(l$data[[1]]$type, "scatter3d")
8999
scene <- l$layout$scene

tests/testthat/test-plotly-colorbar.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ test_that("positioning with multiple colorbars and legends", {
121121

122122
s <- subplot(
123123
plot_ly(z = ~volcano),
124-
plot_ly(x = 1:10, y = 1:10, color = factor(1:10))
124+
plot_ly(x = 1:8, y = 1:8, color = factor(1:8))
125125
)
126126

127127
b <- plotly_build(s)
128128
d <- b$x$data
129-
expect_length(d, 11)
129+
expect_length(d, 9)
130130

131131
expect_true(d[[1]]$colorbar$len == 0.5)
132132
expect_true(d[[1]]$colorbar$lenmode == "fraction")

tests/testthat/test-plotly-linetype.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ test_that("Trace ordering matches factor levels", {
5757
})
5858

5959
test_that("Trace ordering is alphabetical", {
60-
lvls <- sort(unique(mpg$class))
61-
p <- plot_ly(mpg, x = ~cty, y = ~hwy, linetype = ~class) %>% add_lines()
60+
#keep only 6 categories (to avoid warning)
61+
mpg2 <- mpg %>% dplyr::filter(class %in% c("compact", "midsize", "suv", "2seater", "pickup", "subcompact"))
62+
63+
lvls <- sort(unique(mpg2$class))
64+
p <- plot_ly(mpg2, x = ~cty, y = ~hwy, linetype = ~class) %>% add_lines()
6265
l <- expect_traces(p, length(lvls), "alphabetical")
6366
expect_equivalent(sapply(l$data, "[[", "name"), lvls)
6467
})

tests/testthat/test-plotly-name.R

+31
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,34 @@ test_that("doesn't break old behavior", {
4848
expect_equal(l$x$data[[1]]$name, "Fair cut")
4949
expect_equal(l$x$data[[2]]$name, "Ideal cut")
5050
})
51+
52+
53+
test_that("adding trace name with frame does not throw frameOrder warning", {
54+
55+
dt <- data.frame(source = rep(c(rep("TEL", 2) , rep("WEB", 2), rep("OTH",2)),2),
56+
period = rep(c("AM", "PM"), 6),
57+
y_val = runif(12),
58+
year = c(rep(2020,6), rep(2021,6)))
59+
60+
61+
p1 <- plot_ly()
62+
63+
for (yr in unique(dt$year)){
64+
65+
which_lines <- which(dt$year==yr)
66+
67+
p1 <- add_trace(p1,
68+
x = dt$period[which_lines],
69+
y = dt$y_val[which_lines],
70+
frame = dt$source[which_lines],
71+
type = "scatter", mode = "lines+markers",
72+
name = yr)
73+
}
74+
75+
expect_warning(l <- plotly_build(p1), NA)
76+
77+
expect_equal(l$x$data[[1]]$name, 2020)
78+
expect_equal(l$x$data[[2]]$name, 2021)
79+
80+
81+
})

tests/testthat/test-plotly-sf.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ test_that("plot_geo() lat/lon range is set", {
3434
skip_if_not_installed("sf")
3535

3636
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
37-
p <- plotly_build(plot_geo(nc))
37+
expect_warning(p <- plotly_build(plot_geo(nc)),
38+
regexp = "Attempting transformation to the target coordinate system")
3839
expect_equal(
3940
p$x$layout$geo$lataxis$range,
4041
c(33.85492, 36.61673),
@@ -86,7 +87,8 @@ test_that("Can plot sfc with a missing crs", {
8687
skip_if_not_installed("sf")
8788

8889
storms <- sf::st_read(system.file("shape/storms_xyz.shp", package = "sf"), quiet = TRUE)
89-
p <- plotly_build(plot_geo(storms, name = "Storms"))
90+
expect_warning(p <- plotly_build(plot_geo(storms, name = "Storms")),
91+
regexp = "Missing coordinate reference system")
9092
expect_true(p$x$data[[1]]$type == "scattergeo")
9193
expect_true(p$x$data[[1]]$mode == "lines")
9294
})

0 commit comments

Comments
 (0)