本文介绍了以闪亮的方式处理多个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个相对复杂的应用程序,其中包含动态数量的输入,标题为:d1, d2 .. dn.有一次我想尝试同时处理多个输入:
I am building a relatively complicated app, where I have dynamic number of inputs titled:d1, d2 .. dn. At one point I wanted to try addressing multiple inputs at the same time with:
input[[grep(pattern="d+[[:digit:]]",input)]]
这当然导致了错误:
Must use single string to index into reactivevalues
所以我想知道是否有人知道一种优雅的方式来做这样的事情?
So I was wondering whether someone knew an elegant way to do such a thing?
推荐答案
您可以在输入中使用名称:
You can use names on input :
grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE)
一个工作示例:
library("shiny")
ui <- fluidPage(
fluidRow(
column(
width = 6,
lapply(
X = 1:6,
FUN = function(i) {
sliderInput(inputId = paste0("d", i), label = i, min = 0, max = 10, value = i)
}
)
),
column(
width = 6,
verbatimTextOutput(outputId = "test")
)
)
)
server <- function(input, output){
output$test <- renderPrint({
sapply(grep(pattern = "d+[[:digit:]]", x = names(input), value = TRUE), function(x) input[[x]])
})
}
shinyApp(ui = ui, server = server)
这篇关于以闪亮的方式处理多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!