在闪亮的应用程序中基于numericInput创建selectInput()选择

时间:2018-07-06 22:52:40

标签: r shiny

我有一个简单的闪亮应用程序:

#ui.r
navbarPage(
  "Application",
  tabPanel("General",
           sidebarLayout(

             sidebarPanel(
               uiOutput("tex2"),
               br(),
               uiOutput("select")


              ),

             mainPanel(


             )
           )))
#server.r
library(shiny)

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

  output$tex2<-renderUI({
    numericInput("text2","#tests",
                 value = 1,
                 min=1
    )
  })
  output$select<-renderUI({

    selectInput("sel", label = "Select Test",
                for(i in 1:input$text2){
                  choices = list(paste("Test",i) == i)},selected = input$text2

    )


  })

}

如您所见,它包含一个numericInput()和一个selectInput()。我要实现的是基于selectInput()创建numericInput()个选择及其名称。例如,如果我在numericInput()中选择“ 2”,则selectInput()应该有两个选项,名称分别为“ Test1”,“ Test2”。

1 个答案:

答案 0 :(得分:1)

您需要这样的东西,您不需要循环函数参数(选择),只需创建所需的数据并将其传递给参数即可。

output$select<-renderUI({
  selectInput(
    inputId = "sel", 
    label = "Select Test",
    selected = input$text2,
    choices = rep(paste0("Test", 1:input$text2))
  )
})
相关问题