All examples By author By category About

timelyportfolio

plotly + parcoords linked with crosstalk

crosstalk from RStudio, primarily Joe Cheng, will allow both inter- and intra- htmlwidget communication. I will warn crosstalk is still undergoing active development. However, thanks to a lot of effort by @cpsievert, plotly offers the most thorough implementation.

Since Plotly plugs into crosstalk, we can easily control it from the console or another htmlwidget. In this example, we let parcoords and plotly have a conversation. Notice the lines of code required.

code

# note you will need to install from github
#   development versions of crosstalk and parcoords
# devtools::install_github("rstudio/crosstalk@joe/simplify")
# devtools::install_github("timelyportfolio/parcoords@feature/crosstalk2")

library(crosstalk)
library(parcoords)
library(htmltools)
library(plotly)

sd <- crosstalk::SharedData$new(mtcars, group="grp1")

pc <- parcoords(sd, brushMode="1d", reorderable=TRUE)

# try it with plotly as a test
tagList(
  tags$div(style="display:block;float:left;",
    plot_ly(sd, height=400, width=400) %>%
      add_markers(x=~hp, y=~mpg)
  ),
  tags$div(style="display:block;float:left;",
    modifyList(pc,list(height=400, width=600))
  )
) %>%
  browsable()