简体   繁体   中英

accessing inputs created in renderUI in Shiny

I am trying to utilize a bit of dynamic gui activity in an application on Shiny server. My application needs a variable number of sliders created, depending on data that is input into my application. Specifically, I am trying to create sliders that set a value, one for each unique category in a input data table. I am able to successfully read my input table and create the sliders, using render UI, but I am stuck on how to best then manipulate the variable number of created input values set by the sliders - how do I go about accessing them (as a list, preferably?) Appreciate any advice or pointers. My code snippet is below.

output$sliders <- renderUI({

# if we don't need the sliders, return
if (input$unequalpts == "no")
  return(NULL)
# go to panel where sliders are to appear
updateTabsetPanel(session, "inTabSet", selected = "Unequal")
# get the number of unique entries the field f interest to create sliders for
theDATA <- myData()
theFields <- unique(as.character(theDATA$shnystr))

return  (
    lapply(1:numstrata, function(i) {
      sliderInput(inputId = paste0("strata", i), label = paste("strata ", theFields[i]),
                min = 0, max = 100, value = c(0, 100), step = 1)
  })
  ) 
})

It is common to use input$foo to retrieve the value of the input widget that has the id foo . In fact, you can also use input[['foo']] , so in your case, you just pass the id's to input and retrieve their values like this:

lapply(1:numstrata, function(i) {
  input[[paste0("strata", i)]]
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM