Shiny newbie here, struggling with a trivial problem.
Goal: Build a list of names from user input. Each time the user enters a name and clicks Save, append that name to a character vector of names, and update the output with the new contents of that vector.
Problem: Every time they click Save, the character vector has been reinitialized to an empty vector, so the first name is gone, and the new name they entered becomes the only contents of the vector.
ui <- fluidPage(
fluidRow(
textInput("name", "Name:"),
actionButton("btnSave", "Save")
),
fluidRow(
h5("Output:"),
verbatimTextOutput("out")
)
)
server <- function(input, output, session) {
nameList <- as.character(NULL)
observeEvent(input$btnSave, {
newList <- append(nameList, isolate(input$name))
nameList <- reactive(newList)
output$out <- renderPrint(nameList())
})
}