如何使用 shinydashboardPlus 的轮播实现动态数量的幻灯片?

How to implement a dynamic number of slides using shinydashboardPlus' carousel?

我想使用 shinydashboardPlus 的轮播来显示多个图表。这些图表的数量每天从一张到十张不等。

cron 作业每天运行 R 脚本。

这是一个工作示例,其中包含固定数量的幻灯片,三张。

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

chart_names <- c( "http://placehold.it/900x500/39CCCC/ffffff&text=Slide+1", 
                  "http://placehold.it/900x500/39CCCC/ffffff&text=Slide+2",
                  "http://placehold.it/900x500/39CCCC/ffffff&text=Slide+3")


ui <- dashboardPagePlus(

  header = dashboardHeaderPlus(disable = TRUE ),
  sidebar = dashboardSidebar(width = 0 ),

 
  body = dashboardBody(
    carousel(indicators = TRUE,
             id = "mycarousel",
             carouselItem(
               tags$img(src = chart_names[1])
             ),
             carouselItem(
               tags$img(src = chart_names[2])
             ),
             carouselItem(
               tags$img(src = chart_names[3])
             )
    )
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)

这是可以使用 do.call 的示例吗?

constructs and executes a function call from a name or a function and a list of arguments to be passed to it.

本次尝试:

do.call(carousel, as.list(c(id = "mycarousel", "carouselItem(tag$img(src = chart_names[1])")))

导致此错误:

Error: $ operator is invalid for atomic vectors

如何以编程方式将以前未知数量的幻灯片添加到 shinydashboardPlus 轮播?

答案在带有 .list 参数的文档中 ?carousel

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

nb_items = 5

items = Map(function(i) {carouselItem(
  tags$img(src = paste0("http://placehold.it/900x500/39CCCC/ffffff&text=Slide+", i))
)}, 1:5)


ui <- dashboardPagePlus(
  
  header = dashboardHeaderPlus(disable = TRUE ),
  sidebar = dashboardSidebar(width = 0 ),
  
  
  body = dashboardBody(
    carousel(indicators = TRUE,
             id = "mycarousel",
             .list = items
    )
    
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)