accessing inputs created in renderUI in Shiny

ε祈祈猫儿з 提交于 2019-12-22 09:15:12

问题


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)
  })
  ) 
})

回答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)]]
})


来源:https://stackoverflow.com/questions/23705343/accessing-inputs-created-in-renderui-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!