R/Shiny:RenderUI循环生成多个对象 [英] R/Shiny : RenderUI in a loop to generate multiple objects

查看:53
本文介绍了R/Shiny:RenderUI循环生成多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态框成功显示后,请点击此处:

After the success of the dynamic box in shiny here : R/Shiny : Color of boxes depend on select I need you to use these boxes but in a loop. Example : I have an input file which give this :

  • BoxA
  • BoxB
  • BoxC

I want in the renderUI loop these values as a variable to generate dynamically a Box A, B and C. (if I have 4 value, i will have 4 boxes etC.)

Here is my actually code:

for (i in 1:nrow(QRSList))

{ get(QRSOutputS[i]) <- renderUI({ column(4, box(title = h3(QRSList[1], style = "display:inline; font-weight:bold"),

      selectInput("s010102i", label = NULL,
                  choices = list("Non commencé" = "danger", "En cours" = "warning", "Terminé" = "success"),
                  selected = 1) ,width = 12, background = "blue", status = get(QRSIntputS[i])))
  })
  column(4,
observeEvent(input$s010102i,{
  get(QRSOutputS[i]) <- renderUI({
    box(title = h3(QRSList[1], style = "display:inline; font-weight:bold"),

        selectInput("s010102i", label = NULL,
                    choices = list("Not good" = "danger", "average" = "warning", "good" = "success"),
                    selected = get(QRSIntputS[i])) ,width = 12, background = "blue",status = get(QRSIntputS[i]))
  })

The aim is to replace these box names to a variable like input$s010102 for example. But get and assign function does not exist.

Any idea ?

Thanks a lot

解决方案

Here is an example how to generate boxes dynamically

library(shinydashboard)
library(shiny)

QRSList <- c("Box1","Box2","Box3","Box4","Box5")

ui <- dashboardPage(
  dashboardHeader(title = "render Boxes"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Test", tabName = "Test")
    )
  ),

  dashboardBody(
    tabItems(
      tabItem(tabName = "Test",
              fluidRow(
                tabPanel("Boxes",uiOutput("myboxes"))
              )  
      )
    )   
  )
)


server <- function(input, output) {

  v <- list()
  for (i in 1:length(QRSList)){
    v[[i]] <- box(width = 3, background = "blue",
                  title = h3(QRSList[i], style = "display:inline; font-weight:bold"),
                  selectInput(paste0("slider",i), label = NULL,choices = list("Not good" = "danger", "average" = "warning", "good" = "success"))
    )
  }
  output$myboxes <- renderUI(v)
}

shinyApp(ui = ui, server = server)

这篇关于R/Shiny:RenderUI循环生成多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆