I am trying to filter a named list of plotly
objects dynamicaly in R
.
Goal is to display a subset of them inside a subplot according to a datetime range from user. Code has to be runned from a rmarkdown html document or in interactive mode from RStudio.
Current code:
library(crosstalk)
library(plotly)
library(shiny)
library(htmltools)
size <- 5
df <- data.frame(plotly = character(size))
df$plotly <- lapply(1:size, function(x) {
plotly::plot_ly(x = x, y = x, type = "bar")
})
df$date <- as.Date(Sys.Date() - 1:size)
df
shared_plotly_list <- SharedData$new(df, key = ~date)
crosstalk::bscols(
widths = 12,
list(
filter_slider("slider_id_plotly", "Label", shared_plotly_list, ~date),
plotly::subplot(shared_plotly_list$data()$plotly, shareX = TRUE, nrows = length(shared_plotly_list$data()$plotly))
)
)
Output shows all wanted plots without applying any filter. Changing slider values does not update output subplot yet.
Thanks, any help sincerely appreciated.