Couple plot and table on a R shiny app

I am trying to look for examples if any where you can couple the plot and the table from which it is being plotted. As in if you hover or select on a line chart it will hightlight the corresponding data on the table.

Thank you.

If your data is small, an easy way to do this is using crosstalk, see this example: https://rstudio.github.io/crosstalk/index.html

If your data is too large to send to the client all at once, you could consider using server side processing as in this example: https://yihui.shinyapps.io/DT-rows/

4 Likes

Heres an example using plotly and DT. For more plotly-based examples of 'linking views client-side', see -- https://plotly-book.cpsievert.me/linking-views-without-shiny.html

library(plotly)
library(crosstalk)

# `highlight_key()` is essentially the same as using `SharedData$new()`
tx <- highlight_key(txhousing, ~city)

p <- plot_ly(tx) %>%
  group_by(city) %>%
  add_lines(x = ~date, y = ~median)

bscols(p, DT::datatable(tx))
1 Like