JasonAizkalns
JasonAizkalns

Reputation: 20463

How to use crosstalk, reactable, and plotly parcoords in R

I am trying to use reactable and plotly together with brushing. I would think something like this would work:

library(plotly)
library(reactable)
library(crosstalk)
library(dplyr)

# Sample data (iris dataset)
data <- iris

# Create a SharedData object for Crosstalk
shared_data <- SharedData$new(data)

# Create a reactable table
tbl <- reactable(
  shared_data,
  selection = "multiple",
  onClick = "select",
  highlight = TRUE
)

# Create a parallel coordinates plot using plotly
parallel_plot <- plot_ly(
  shared_data, 
  type = 'parcoords',
  dimensions = list(
    list(range = range(data$Sepal.Length), label = 'Sepal Length', values = ~Sepal.Length),
    list(range = range(data$Sepal.Width), label = 'Sepal Width', values = ~Sepal.Width),
    list(range = range(data$Petal.Length), label = 'Petal Length', values = ~Petal.Length),
    list(range = range(data$Petal.Width), label = 'Petal Width', values = ~Petal.Width)
  )
)

# Combine plot and table using crosstalk
bscols(tbl, parallel_plot)

enter image description here

However, brushing the parallel coordinates plot does nothing to the reactable. In addition, clicking a reactable row does not highlight the plotly plot, but it does do something weird to the first scale: Sepal.Length.

Interestingly, if I use the parcoords package, things work correctly (see below), but I'd prefer to find a way to make this work with plotly.

parallel_plot_parcoords <- parcoords::parcoords(
  shared_data,
  brushMode = "1D-axes",
  alpha = 0.3
)

bscols(tbl, parallel_plot_parcoords)

enter image description here

Upvotes: 4

Views: 214

Answers (0)

Related Questions