Skip to content

Commit 757a329

Browse files
committed
Close #1920: group_by.plotly() now retains crosstalk set information
1 parent 97096fc commit 757a329

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

R/plotly_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ ungroup.plotly <- function(x, ...) {
131131

132132
#' @rdname plotly_data
133133
group_by.plotly <- function(.data, ...) {
134-
d <- group_by(plotly_data(.data), ...)
134+
d <- preserve_set(plotly_data(.data), group_by, ...)
135135
if (crosstalk_key() %in% names(d)) {
136-
d <- group_by_add(d, !!rlang::sym(crosstalk_key()), add = TRUE)
136+
d <- preserve_set(d, group_by_add, !!rlang::sym(crosstalk_key()))
137137
}
138138
add_data(.data, d)
139139
}

tests/testthat/test-animate-highlight.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ test_that("Simple scatterplot brushing with plot_ly() and subplot()", {
7070
})
7171

7272

73+
test_that("group_by.plotly() retains crosstalk set", {
74+
b <- mtcars %>%
75+
crosstalk::SharedData$new(group = "foo") %>%
76+
plot_ly(x = ~mpg, y = ~hp) %>%
77+
group_by(am) %>%
78+
add_markers() %>%
79+
plotly_build()
80+
expect_equal(b$x$data[[1]]$set, "foo")
81+
expect_true(all(b$x$data[[1]]$key == row.names(mtcars)))
82+
})
83+
84+
7385

7486
# Ignore for now https://github.com/ggobi/ggally/issues/264
7587
#test_that("SharedData produces key/set in ggpairs", {

0 commit comments

Comments
 (0)