访问在Shiny中的renderUI中创建的输入 [英] accessing inputs created in renderUI in Shiny
问题描述
我正尝试在Shiny服务器上的应用程序中使用一些动态gui活动。我的应用程序需要创建可变数量的滑块,具体取决于输入到我的应用程序中的数据。具体来说,我正在尝试创建一个设置值的滑块,一个用于输入数据表中每个唯一的类别。我能够成功地读取我的输入表并使用render UI创建滑块,但是我坚持如何最好地操纵由滑块设置的创建的输入值的变量数量 - 我如何去访问它们(作为列表,最好?)欣赏任何建议或指针。我的代码片段在下面。
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)
})
)
})
推荐答案
通常使用输入$ foo
来检索具有id foo
的输入小部件的值。其实你也可以使用输入[['foo']]
,所以在你的情况下,你只需将id传递给输入
并检索它们的值:
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)]]
})
这篇关于访问在Shiny中的renderUI中创建的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!