简体   繁体   English

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

[英]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.

相关问题 shinydashboardPlus 的旋转木马 - 不出现雪佛龙 - shinydashboardPlus' carousel - Chevrons do not appear 在 R Shiny 中创建和删除动态框使用 shinydashboardplus package (boxDropdownItem) - Creation and deletion of dynamic boxes in R Shiny using shinydashboardplus package (boxDropdownItem) bsplus:Shouse中动态数量的旋转木马 - bsplus: Carousel for dynamic number of plots in Shiny R shinydashboardplus 翻转框 - 如何删除图像 - R shinydashboardplus flipbox - how to remove images 将动态图片 url 链接传递到 shinydashboardPlus() 中的 UI 不起作用 - Passing dynamic picture url link to UI in shinydashboardPlus() not working 如何使用 R 将饼图保存到 ppt 幻灯片中? - How to save Pie chart into ppt slides using R? 如何使用包官从 Shiny 更新 PowerPoint 幻灯片? - How to update PowerPoint slides from Shiny by using the package officer? 如何使用Rpres降价获得垂直幻灯片 - How do I get vertical slides using Rpres markdown 使用 bs4Dash 时更改 shinydashboardPlus 左右侧边栏的颜色 package - Change the color of left and right sidebar in shinydashboardPlus when using bs4Dash package 如何在不使用for循环的情况下在R中实现动态计数? - How can I implement a dynamic count within R without using a for loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM