Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using dplyr 1.0.4., plot with controls created by crosstalk and plotly is not interactive any more #5760

Closed
fjodor opened this issue Feb 12, 2021 · 5 comments · Fixed by #5767
Assignees
Milestone

Comments

@fjodor
Copy link

fjodor commented Feb 12, 2021

Thanks for looking into this, Romain!

Using remotes::install_github("tidyverse/dplyr"), I get dplyr version 1.0.4.9000. Get the same image that you posted, but the slider and the checkboxes have no effect on the plot, which they do when using dplyr version 1.0.2., or commenting out group_by() .

Originally posted by @fjodor in #5726 (comment)

@fjodor fjodor changed the title Thanks for looking into this, Romain! Using dplyr 1.0.4., plot with controls created by crosstalk and plotly is not interactive any more Feb 12, 2021
@fjodor
Copy link
Author

fjodor commented Feb 12, 2021

Since updating dplyr, a plotly chart linked with a slider and a checkbox via crosstalk does not react to the controls any more. The following code works with dplyr version 1.0.2. In versions 1.0.3 and 1.0.4 I need to comment out the group_by() statement to make it work. Using the current development version of dplyr, 1.0.4.9000, did not help on my system.

@fjodor
Copy link
Author

fjodor commented Feb 12, 2021

library(plotly)
library(crosstalk)

shared_data <- mtcars %>% 
  SharedData$new()

p <- shared_data %>% 
  plot_ly(x = ~mpg, y = ~hp) %>%
  group_by(am) %>%
  add_markers()

bscols(list(
  filter_slider(id = "mpg", label = "Miles per Gallon",
                sharedData = shared_data, column = "mpg"),
  filter_checkbox(id = "am", label = "Automatic / Manual",
                  sharedData = shared_data, group = ~am)),
  p)

@fjodor
Copy link
Author

fjodor commented Feb 12, 2021

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] **crosstalk_1.1.1 plotly_4.9.3 ggplot2_3.3.3**

loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 pillar_1.4.7 compiler_4.0.3 later_1.1.0.1 tools_4.0.3
[6] digest_0.6.27 jsonlite_1.7.2 lifecycle_0.2.0 tibble_3.0.6 gtable_0.3.0
[11] viridisLite_0.3.0 pkgconfig_2.0.3 rlang_0.4.10 shiny_1.6.0 DBI_1.1.1
[16] yaml_2.2.1 fastmap_1.1.0 withr_2.4.1 **dplyr_1.0.4.9000** httr_1.4.2
[21] generics_0.1.0 vctrs_0.3.6 htmlwidgets_1.5.3 grid_4.0.3 tidyselect_1.1.0
[26] glue_1.4.2 data.table_1.13.6 R6_2.5.0 purrr_0.3.4 tidyr_1.1.2
[31] magrittr_2.0.1 promises_1.2.0.1 scales_1.1.1 ellipsis_0.3.1 htmltools_0.5.1.1
[36] assertthat_0.2.1 xtable_1.8-4 mime_0.9 colorspace_2.0-0 httpuv_1.5.5
[41] lazyeval_0.2.2 munsell_0.5.0 crayon_1.4.1

@romainfrancois
Copy link
Member

cc @cpsievert

@cpsievert
Copy link
Contributor

cpsievert commented Feb 15, 2021

This happens because plotly is essentially assuming that group_by(..., .add = TRUE) will preserve attributes, which seems to no longer be the case when a group(s) get added:

m <- mtcars
attr(m, "foo") <- "a"
m <- dplyr::group_by(m, vs)
attr(m, "foo")
#> [1] "a"
m <- dplyr::group_by(m, cyl, .add = TRUE)
attr(m, "foo")
#> NULL

I can make a fix for this in plotly, but maybe also something you want to address in dplyr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants