R/Shiny :循环中的 RenderUI 生成多个对象

SMA*_*MAX 1 html user-interface r shiny

在闪亮的动态框成功后:R/Shiny:框的颜色取决于选择我需要您在循环中使用这些框。\n示例:\n我有一个输入文件,其中给出了以下内容:

\n\n
    \n
  • A盒
  • \n
  • 盒子B
  • \n
  • 盒C
  • \n
\n\n

我希望在 renderUI 循环中将这些值作为变量来动态生成框 A、B 和 C。(如果我有 4 个值,我将有 4 个框等。)

\n\n

这是我的实际代码:

\n\n
for (i in 1:nrow(QRSList))\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n
      selectInput("s010102i", label = NULL,\n                  choices = list("Non commenc\xc3\xa9" = "danger", "En cours" = "warning", "Termin\xc3\xa9" = "success"),\n                  selected = 1) ,width = 12, background = "blue", status = get(QRSIntputS[i])))\n  })\n  column(4,\nobserveEvent(input$s010102i,{\n  get(QRSOutputS[i]) <- renderUI({\n    box(title = h3(QRSList[1], style = "display:inline; font-weight:bold"),\n\n        selectInput("s010102i", label = NULL,\n                    choices = list("Not good" = "danger", "average" = "warning", "good" = "success"),\n                    selected = get(QRSIntputS[i])) ,width = 12, background = "blue",status = get(QRSIntputS[i]))\n  })\n
Run Code Online (Sandbox Code Playgroud)\n\n

目的是将这些框名称替换为像 input$s010102 这样的变量。但get和assign函数不存在。

\n\n

任何想法 ?

\n\n

多谢

\n

Por*_*hop 6

这是如何动态生成盒子的示例

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述