Skip to content

Commit

Permalink
Close #1920: group_by.plotly() now retains crosstalk set information
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Feb 16, 2021
1 parent 97096fc commit 757a329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/plotly_data.R
Expand Up @@ -131,9 +131,9 @@ ungroup.plotly <- function(x, ...) {

#' @rdname plotly_data
group_by.plotly <- function(.data, ...) {
d <- group_by(plotly_data(.data), ...)
d <- preserve_set(plotly_data(.data), group_by, ...)
if (crosstalk_key() %in% names(d)) {
d <- group_by_add(d, !!rlang::sym(crosstalk_key()), add = TRUE)
d <- preserve_set(d, group_by_add, !!rlang::sym(crosstalk_key()))
}
add_data(.data, d)
}
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-animate-highlight.R
Expand Up @@ -70,6 +70,18 @@ test_that("Simple scatterplot brushing with plot_ly() and subplot()", {
})


test_that("group_by.plotly() retains crosstalk set", {
b <- mtcars %>%
crosstalk::SharedData$new(group = "foo") %>%
plot_ly(x = ~mpg, y = ~hp) %>%
group_by(am) %>%
add_markers() %>%
plotly_build()
expect_equal(b$x$data[[1]]$set, "foo")
expect_true(all(b$x$data[[1]]$key == row.names(mtcars)))
})



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

0 comments on commit 757a329

Please sign in to comment.