Crosstalk beween plotly and DT with multiple selection

crosstalk

#1

[Note: although I’m posting under the ‘shiny’ heading, I’d rather keep this server-free if possible]

I’m struggling to have an interactive selection that updates both a plotly object and a datatable. It works fine with one point, but when I set options(persistent = TRUE) to enable multiple selections the selected rows don’t match up. Any idea?

---
title: testing interaction
output: html_document
---

```{r, echo=FALSE,warning=FALSE,message=FALSE}
library(crosstalk)
library(plotly)
library(DT)

d <- data.frame(x=1:10,y=1:10,f=gl(2,5,labels = letters[1:2]))
sd <- SharedData$new(d)

# options(persistent = TRUE)

p <- ggplot(sd, aes(x, y)) +
  geom_text(aes(label=f)) +
  theme_void() 

bscols(
  ggplotly(p) %>%
    highlight(color = "red",on = "plotly_click"),
  datatable(sd, style="bootstrap", class="compact", width="100%",
            options=list(deferRender=FALSE, dom='t')))
    
```

Incorrect output with options(persistent = TRUE),

sessionInfo()
R version 3.4.3 Patched (2017-12-15 r73919)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_NZ.UTF-8/en_NZ.UTF-8/en_NZ.UTF-8/C/en_NZ.UTF-8/en_NZ.UTF-8

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

other attached packages:
[1] ggplot2_2.2.1.9000 tibble_1.4.2       tidyr_0.7.2        purrr_0.2.4       
[5] plyr_1.8.4         yaml_2.1.16        crosstalk_1.0.1   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.15      compiler_3.4.3    pillar_1.1.0      git2r_0.20.0      tools_3.4.3      
 [6] digest_0.6.15     evaluate_0.10.1   memoise_1.1.0     gtable_0.2.0      rlang_0.1.6.9003 
[11] shiny_1.0.5       curl_3.1          withr_2.1.1.9000  httr_1.3.1        stringr_1.2.0    
[16] knitr_1.18        htmlwidgets_1.0   devtools_1.13.4   rprojroot_1.3-1   grid_3.4.3       
[21] DT_0.4            glue_1.2.0        R6_2.2.2.9000     rmarkdown_1.8     magrittr_1.5     
[26] backports_1.1.2   scales_0.5.0.9000 htmltools_0.3.6   rsconnect_0.8.5   mime_0.5         
[31] xtable_1.8-2      colorspace_1.3-2  httpuv_1.3.5      labeling_0.3      stringi_1.1.6    
[36] lazyeval_0.2.1    munsell_0.4.3   

#2

Seems to work okay with persistent TRUE and FALSE on my machine. Update your packages? Here’s a screenshot of it working

 sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8   
 [6] LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] DT_0.4.1           plotly_4.7.1.9000  ggplot2_2.2.1.9000 crosstalk_1.0.0   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.15        bindr_0.1           compiler_3.4.3      pillar_1.1.0        git2r_0.21.0        plyr_1.8.4          tools_3.4.3        
 [8] digest_0.6.15       viridisLite_0.3.0   jsonlite_1.5        evaluate_0.10.1     memoise_1.1.0       tibble_1.4.2        gtable_0.2.0       
[15] pkgconfig_2.0.1     rlang_0.1.6.9003    shiny_1.0.5         curl_3.1            yaml_2.1.16         bindrcpp_0.2        withr_2.1.1.9000   
[22] httr_1.3.1          stringr_1.2.0       dplyr_0.7.4         knitr_1.19          htmlwidgets_1.0     devtools_1.13.4     rprojroot_1.3-2    
[29] grid_3.4.3          glue_1.2.0          data.table_1.10.4-3 R6_2.2.2            rmarkdown_1.8       tidyr_0.8.0         purrr_0.2.4        
[36] magrittr_1.5        backports_1.1.2     scales_0.5.0.9000   htmltools_0.3.6     rsconnect_0.8.5     assertthat_0.2.0    mime_0.5           
[43] xtable_1.8-2        colorspace_1.3-2    httpuv_1.3.5        labeling_0.3        stringi_1.1.6       lazyeval_0.2.1.9000 munsell_0.4.3           

#3

Thanks, I’ve just updated DT and it seems to work now. It appears that this got fixed just as I was struggling with the unexpected behaviour, I should have thought to check the github issues but I thought I was using it wrong.