【发布时间】:2016-07-25 17:42:31
【问题描述】:
我已经通过 renderUI() 成功地更新了 UI。我有一长串可供选择的输入。复选框用于动态添加数字输入。因此,为了实现这一点,我使用了 lapply。但是,我使用了 checkboxgroup 本身中选定复选框的值来填充动态添加的数字输入的 ID,而不是在 lapply 中使用 paste(input, i)。
用户界面代码 sn-p:
checkboxGroupInput(inputId = "checkboxgrp", label = "Select types",
choices = list("ELECTAPP","NB W $","PUR","MANUAL LTR","REDEMPTION","NB W TRANSFER","NB WOUT $","OUTPUT")),
...
fluidRow(column(12, verbatimTextOutput("value")))
...
uiOutput("numerics")
服务器代码 sn-p:
renderUI({
numInputs <- length(input$checkboxgrp)
if(numInputs==0){
wellPanel("No transaction selected")
}
else{
lapply(1:numInputs, function(i){
x[i]=input$checkboxgrp[i]
list(numericInput(input$checkboxgrp[i], min = 0, label = input$checkboxgrp[i],
value= input[[x[i]]] ))
})
}
})
output$value <- renderPrint({
numInputs <- length(input$checkboxgrp)
lapply(1:numInputs, function(i){
print(input[[x[i]]]) ## ERROR
})
})
我使用input[[x[i]]] 来实例化添加或删除数字输入后要保留的值。但是,我想将 input$x[i] 或 input[[x[i]]] 中的值提取到一个向量中以供进一步使用,这是我无法做到的。
*ERROR:Must use single string to index into reactivevalues
感谢任何帮助。
编辑
使用 3 种不同的方式从输入中提取值会产生 3 种不同的错误:
使用print(input$x[i]) # ERROR
NULL
NULL
NULL
NULL
[[1]]
NULL
[[2]]
NULL
[[3]]
NULL
[[4]]
NULL
使用print(input[[x[i]]]) # ERROR
Must use single string to index into reactivevalues
使用print('$'(input, x[i])) # ERROR
invalid subscript type 'language'
【问题讨论】:
标签: r shiny dynamic-ui