Reputation: 367
In Shiny, is it possible to create several reactive input-output pairs from a vector/list of strings using a functional?
i.e something like
id_list <- c("ID_1", "ID_2", "ID_3")
server <- function(input, output) {
lapply(id_list, function(x) quote(output$as.character(x) <- renderText({ input$x })))
}
The result would in effect be
output$ID_1 <- renderText({ input$ID_1 })
output$ID_2 <- renderText({ input$ID_2 })
output$ID_2 <- renderText({ input$ID_2 })
etc. for all items in the list, with each working in a reactive manner in the server function.
Upvotes: 0
Views: 75
Reputation: 84529
server <- function(input, output) {
for(id in id_list){
local({
localId <- id
output[[localId]] <- renderText({
input[[localId]]
})
})
}
}
Upvotes: 1