title: Shiny app with crosstalk and different interactive plots and tables
body: <p>I want to build a shiny application that allows the user to interact with different plots and tables that are linked. To be precise, plot1 shows the raw data as a scatter plot, plot2 shows the data in an aggregated barplot, and finally table1 shows the data aggregated by another variable.</p>
  <p>For example using <code>ggplot2::mpg</code>, I want hwy vs cty in plot1; plot2 shows the average hwy by manufacturer; and table1 shows the average hwy by drv.
  The important bit is that when the user selects <code>drv == &quot;r&quot;</code> in the table, plot1 and plot2 should be reactive to that. Similarly, if a range is selected in plot1, then plot2 and table1 should show the values for the filtered data only, similarly, if a group is excluded by clicking on the legend in plot2, eg <code>drv != &quot;r&quot;</code>, then that should be applied to the other data as well.</p>
  <p>Using basic shiny I would create a reactive dataset which is filtered by the selection of each plot/table, but this feels a little bit too complicated for the task at hand.</p>
  <p>This seems to be the perfect example for <code>crosstalk</code> but I am not able to get it to work.
  For a simple example, I was using <code>echarts4r</code> for the interactivity.</p>
  <h1>MWE</h1>
  <p>An MWE looks like this:</p>
  <pre><code>library(dplyr)     # for aggregating the data
  library(ggplot2)   # for the mpg dataset
  library(shiny)     # ...
  library(crosstalk) # ...
  library(reactable) # interactive tables 
  library(echarts4r) # interactive charts
  
  # 1. Create the shared datasets =====
  sd_raw &lt;- SharedData$new(mpg, group = &quot;mpg&quot;)
  
  sd_by_man &lt;- as_tibble(mpg) |&gt; 
    group_by(manufacturer, drv) |&gt; 
    summarise(n = n(), mean_hwy = mean(hwy)) |&gt; 
    SharedData$new(group = &quot;mpg&quot;)
  
  sd_by_drv &lt;- as_tibble(mpg) |&gt; 
    group_by(drv) |&gt; 
    summarise(n = n(), mean_hwy = mean(hwy)) |&gt; 
    SharedData$new(group = &quot;mpg&quot;)
  
  
  # 2. Define shiny UI ====
  ui &lt;- fluidPage(
    fluidRow(
      column(4, echarts4rOutput(&quot;plot1&quot;)),
      column(4, echarts4rOutput(&quot;plot2&quot;)),
      column(4, reactableOutput(&quot;table1&quot;))
    )
  )
  
  # 3. Define shiny Server ====
  server &lt;- function(input, output, session) {
    output$plot1 &lt;- renderEcharts4r({
      # apparently echarts4r and group_by do not play well with sd_raw, but need
      # the $data() element
      sd_raw$data() |&gt; 
        group_by(drv) |&gt; 
        e_charts(hwy) |&gt; 
        e_scatter(cty, ) |&gt; 
        e_tooltip() |&gt; 
        e_brush()
    })
    output$plot2 &lt;- renderEcharts4r({
      sd_by_man$data() |&gt; 
        group_by(drv) |&gt; 
        e_charts(manufacturer, stack = &quot;drv&quot;) |&gt; 
        e_bar(mean_hwy) |&gt; 
        e_tooltip() |&gt; 
        e_brush()
    })
    output$table1 &lt;- renderReactable({
      reactable(
        sd_by_drv$data(),
        selection = &quot;multiple&quot;,
        onClick = &quot;select&quot;,
        rowStyle = list(cursor = &quot;pointer&quot;),
        minRows = 10
      )
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  <p>Which results in an app like this</p>
  <p><a href="https://i.stack.imgur.com/XoFhf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XoFhf.png" alt="example app" /></a></p>
  <p>Note that the app looks correct, but for example</p>
  <ul>
  <li>selecting a drv in the table does not change the plots, or</li>
  <li>de-selecting a drv does not change the other outputs, or</li>
  <li>brushing an area on the first plot also does not change the other outputs.</li>
  </ul>
  <p>Any idea how to get this interactivity to work? Can this be done using crosstalk or do I need to resort back to using basic shiny reactivity (which of course would make the app a lot more complicated...)</p>