[英]How to implement a dynamic number of slides using shinydashboardPlus' carousel?
I wish to use shinydashboardPlus' carousel to display a number of charts.我希望使用 shinydashboardPlus 的轮播来显示许多图表。 The number of these charts can vary on a daily basis from one to ten.
这些图表的数量每天可以从 1 到 10 不等。
A cron job runs the R script daily. cron 作业每天运行 R 脚本。
Here is a working example with a fixed number of slides, three.这是一个具有固定数量幻灯片的工作示例,三张。
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)
Is this an example of where do.call
could be used?这是可以在哪里使用
do.call
的示例吗?
constructs and executes a function call from a name or a function and a list of arguments to be passed to it.
从名称或 function 和要传递给它的 arguments 列表构造并执行 function 调用。
This attempt:这次尝试:
do.call(carousel, as.list(c(id = "mycarousel", "carouselItem(tag$img(src = chart_names[1])")))
results in this error:导致此错误:
Error: $ operator is invalid for atomic vectors
How do I programmatically add a previously unknown number of slides to a shinydashboardPlus carousel?如何以编程方式将以前未知数量的幻灯片添加到 shinydashboardPlus 轮播?
The answer was in the doc with the.list parameter?carousel答案在带有 .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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.