1

I am trying to link two plotly plots in R using Crosstalk. Can someone please tell me why the example below is not working when I try to do a rectangular selection on one of the plots:

library(plotly)
library(crosstalk)

mtcars_sd <- SharedData$new(data = mtcars, key = rownames(mtcars))

p1 <- plot_ly(data = mtcars_sd, x=~mpg, y =~drat) %>% 
    add_markers()


p2 <- plot_ly(data = mtcars_sd, x=~wt, y =~hp) %>% 
    add_markers()

mtcars_linked_plots <- plotly::subplot(p1, p2, titleX = TRUE, titleY = TRUE) %>% 
    hide_legend() 

mtcars_linked_plots %>% 
    highlight(on = "plotly_click")

I could use the plotly_selected option for on in highlight but I want the plot to resize the axes on selection that is why I am using plotly_click

Aous Abdo
  • 11
  • 2
  • Works fine on my machine. When I click on one point the respective point in the other plot gets highlighted as well. – stefan Sep 19 '22 at 19:33
  • Thank you Stefan. I am trying to do a rectangular selection and not just highlight a point. Any ideas? – Aous Abdo Sep 19 '22 at 19:42

0 Answers0