I have a generic function to create a series of inputs with from a vector of IDs / names. I want to use that vector of IDs to create a table showing the each of these inputs. My issue is that I can't figure out how to use input$<id>
to return the actual input. I tried pasting strings (e.g., paste0("input$id", input_names[1]
) and converting to other types but no luck.
The goal is to change the input_names
variable and have those changes propagate to the dependent app elements.
library(shiny)
library(tidyverse)
generic_numeric_input <- function(id, ...){
numericInput(inputId = id, label = id, ...)
}
input_names <- c("x", "y")
ex_inputs <- map(input_names, generic_numeric_input, value = 3)
shinyApp(
ui = fluidPage(
ex_inputs,
tableOutput("ex_table")
),
server = function(input, output, session) {
output$ex_table <- renderTable(tibble(
# how can I make this change along with input_names?
"x" = input$x,
"y" = input$y
))
}
)
Created on 2021-04-25 by the reprex package (v2.0.0)