Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly crosstalk issue

I am unable to get the following example for Crosstalk to work using Plotly: https://beta.rstudioconnect.com/jcheng/shiny-crosstalk/.

I updated the variables references to match the latest Plotly requirements (~ to represent the variables). However, the behavior is not the same as expected. The plots are not all rendering via the Shared Crosstalk object.

I suppose the question is, is there a working example of Crosstalk and Plotly where selecting values in onw widget instantly highlights on another plotly chart? It seems with ggplot this works fine. https://gallery.shinyapps.io/crosstalk_04_ggplot2/.

My understanding is that plotly widgets are compatible with crosstalk. Is that correct?

Hey @ahsanshah

To answer your question about Plotly and Crosstalk here is a working example:

# devtools::install_github("ropensci/plotly")
library(plotly)
library(crosstalk) 

d <- SharedData$new(mtcars)
scatterplot <- plot_ly(d, x = ~mpg, y = ~disp) %>%
  add_markers(color = I("black")) %>%
  layout(dragmode = "select")

subplot(
  plot_ly(d, y = ~disp, color = I("black")) %>% 
    add_boxplot(name = "overall"),
  scatterplot, shareY = TRUE
) %>% layout(dragmode = "select")

You can read more about linked views without shiny here https://cpsievert.github.io/plotly_book/linking-views-without-shiny.html

Also, there was a webinar, you may be interested in, that talked about linking,brushing,highlighting, and etc. https://www.crowdcast.io/e/plotly-for-R (slides from the webinar https://cpsievert.github.io/plotcon17/webinar/#1).

Thanks. I suppose I have a general question on “linked brushing”. Do we consider linked brushing to be “immediate change” of linked rows in a Shared object or a “post select” render? The reason I ask is in the d3scatter example from Joe Cheng, it seems to be the former. Basically, as I hover over one plot the markers in another plot will render. This is fundamentally different than once I select a region the other plot will update. Here is another example of this with crossfilter: http://square.github.io/crossfilter/

I am currently using the click_events in Plotly and Shiny which to a degree links plots (including DataTable, Leaflet, etc). What exactly does cross talk offer for Plotly in Shiny? From what Carson has documented here: https://cpsievert.github.io/plotly_book/linking-views-without-shiny.html, it seems within Shiny we dont really use crosstalk?

Essentially, my questions are:

  1. Does crosstalk/plotly allow for dynamic/immediate linked brushing as is shown with d3scatter and crossfiler?
  2. If I use R/Shiny/Plotly anyways, what value does crosstalk bring or is it not really needed in this scenario?

Any input on this would be great.

Thanks,

Ahsan

By immediate, I assume you mean ‘do all the linked plots update while dragging the brush’? At least for the near term, this won’t be possible.

Since the visualization doesn’t depend on shiny, it is easier to share. There is also usually less “boilerplate code”.

Thanks for the clarification. It would be great if eventually we could do the updates while dragging. I believe leaflet does this currently. Visually that type of linkage would be very powerful.