Plotly gauge graph and crosstalk filtering for flexdashboard

302 Views Asked by At

I am trying the create a plotly gauge graph for a flexdashboard which should change value depending on the chosen filter in crosstalk::filter_select().

I have tried and tried but cannot get the filter to work. This is an example with mtcars of what I am trying to do. I noticed that if the SharedData object has only one value, then it works, but otherwise plotly does not show any data.

mtcars_data <- tibble::rownames_to_column(mtcars, "Car")

shared_mtcars <- SharedData$new(mtcars_data)
row1 <- bscols(filter_select("Car", "Car", shared_mtcars, ~Car, multiple = F)
)

fig <- plot_ly(shared_mtcars, 
  domain = list(x = c(0, 1), y = c(0, 1)),
  value = ~mpg,
  title = list(text = "MPG"),
  type = "indicator",
  mode = "gauge+number")

bscols(row1, fig, widths = 12)

This code results in a graph with no data. If I subset mtcars_data to take the first row or the first two rows (which happen to have the same value for mpg) then it works. If I subset rows 1 and 3, it doesn't.

I might be missing something - in that case would really appreciate any feedback.

0

There are 0 best solutions below