Addressing multiple inputs in shiny

前端 未结 1 1495
挽巷
挽巷 2020-12-10 20:04

I am building a relatively complicated app, where I have dynamic number of inputs titled: d1, d2 .. dn. At one point I wanted to try addressing multiple inputs at the same t

相关标签:
1条回答
  • 2020-12-10 20:08

    You can use names on input :

    grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE)
    

    A working example :

    library("shiny")
    ui <- fluidPage(
      fluidRow(
        column(
          width = 6,
          lapply(
            X = 1:6,
            FUN = function(i) {
              sliderInput(inputId = paste0("d", i), label = i, min = 0, max = 10, value = i)
            }
          )
        ),
        column(
          width = 6,
          verbatimTextOutput(outputId = "test")
        )
      )
    )
    server <- function(input, output){
      output$test <- renderPrint({
        sapply(grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE), function(x) input[[x]])
      })
    }
    shinyApp(ui = ui, server = server)
    
    0 讨论(0)
提交回复
热议问题