How to link two plots in R using Crosstalk and Plotly

Viewed 19

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

0 Answers
Related