Last active
September 7, 2023 11:51
-
-
Save christopherlovell/b7ecdf8b0aa82c20fa46 to your computer and use it in GitHub Desktop.
Shiny dynamic UI elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
server <- function(input, output) { | |
output$input_ui <- renderUI({ | |
num <- as.integer(input$num) | |
lapply(1:num, function(i) { | |
numericInput(paste0("n_input_", i), label = paste0("n_input", i), value = 0) | |
}) | |
}) | |
output$table <- renderTable({ | |
num <- as.integer(input$num) | |
data.frame(lapply(1:num, function(i) { | |
input[[paste0("n_input_", i)]] | |
})) | |
}) | |
} | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("num", "select number of inputs", choices = seq(1,10,1)) | |
), | |
mainPanel( | |
uiOutput("input_ui"), | |
tableOutput("table") | |
) | |
) | |
) | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment