I'm using renderUI in shiny to create text fields depending on the user's selection. The user then fills out the fields and in the simplified version below, the goal is to display the results. How can I get the data from uiOutput?
I thought the answer to this question would help: How to get the value in uioutput in ui.R and send it back to server.R? but it doesn't work for my app.
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel("data", fluid = TRUE,
sidebarLayout(
sidebarPanel(selectInput(inputId = "age2", label = "Select", choices = c("young", "old")),
actionButton("goButton", "Go!"),
uiOutput("variables")),
mainPanel(verbatimTextOutput("print"))))
)
)
server <- function(input, output, session) {
output$variables <- renderUI({
switch(input$age2,
"young" = numericInput("this", "This", value = NULL),
"old" = numericInput("that", "That", value = NULL)
)
})
x <- eventReactive(input$goButton, {
input$variables
})
output$print <- renderText({
x()
})
}
shinyApp(ui = ui, server = server)