I have some inputs that are generated or eliminated if some actionButtons are activated. However, the input value is reset each time any actionButton is activated. I know this is because the inputs are rendered each time one of the actionButton are pressed. So is there a way to get a hold of the values selected? I though of render each on his own uiOutput, but I don't know how to do that dynamically as in this approach. That or any other implementation is greatly appreciated.
Reprex:
library(shiny)
ui <- fluidPage(
actionButton("addInput", "Agregar"),
actionButton("removeInput", "Eliminar"),
uiOutput("inputs"),
h3("When you select any value from any input and then press an actionButton, the values are lost because the inputs are rendered once again. How can I keep the values selected even after adding or deletion of a new input?")
)
server <- function(input, output, session) {
i <- reactive({
i <- input$addInput - input$removeInput
if(i <= 0 ){
i <- 1 }
return(i)
})
output$inputs <- renderUI({
if (is.null(i())) return(NULL)
tagList(
lapply(1:i(),function(j){
shiny::selectInput(paste0('vble_',i()[j]), '', choices = c(LETTERS))
})
)
})
}
shinyApp(ui, server)