Dataminer
Dataminer

Reputation: 1549

Dynamic input widgets in Shiny

I am building a Shiny app which includes dynamic input widgets. I can do this by using uiOutput() & renderUI(). My server side code is as follows:

output$dynamic_widget <- renderUI({

    num <- as.integer(input$slider_val)
    lapply(1:num,function(i) {

      textInput(inputId = paste("text",i+1),label="Dynamic text inputs",value="")
       })

  })

Where slider_val refers to a slider input in my UI. Now, as I change the value of the slider I can add dynamic text inputs on the fly.

This part of the code works fine. However, my question is, how do I access the values of these dynamic widgets, using variable names. I would like to do something like this:

for(i in 1:length(input$slider_val)) {
   output[[i]] <- input$.... #access the value of ith text input widget
}

i.e I would like to access the values of each dynamic widget and store the values in a list.

How could I do this?

Thanks!

Upvotes: 0

Views: 802

Answers (1)

Tonio Liebrand
Tonio Liebrand

Reputation: 17719

You can access your input the same way you assigned values to your output:

for(i in 1:as.numeric(input$slider_val)) {
   output[[i]] <- input[[paste("text",i+1)]] #access the value of ith text input widget
}

Upvotes: 1

Related Questions