Reputation: 78927
This is a follow up question to this Avoid DRY with 13 sliderInputs and 13 textInputs:
How can I shorten this code:
sliderValues <- reactive({
data.frame(
Name = c("A",
"B",
"C"),
Value = as.character(c(input$a,
input$b,
input$c
)),
stringsAsFactors = FALSE)
})
I have tried:
# Reactive expression to create data frame of all input values ----
sliderValues <- reactive({
data.frame(
Name = c(LETTERS[1:3]),
Value = paste0("input$", letters[1:3]),
stringsAsFactors = FALSE)
})
Upvotes: 1
Views: 215
Reputation: 124148
One option would be to use sapply
or ...
# Reactive expression to create data frame of all input values ----
sliderValues <- reactive({
data.frame(
Name = c("A",
"B",
"C"),
Value = as.character(sapply(letters[1:3], function(x) input[[x]])),
stringsAsFactors = FALSE)
})
Upvotes: 3