How can I clean the "input" (the verbatimTextOutput("summary") in the example bellow) after removing some element.
I tried some thing using shiny.unbindAll
without succes.
the dedicated removeUI
doesnt do the job.
Please have a look to this example :
library(shiny)
ui <- fluidPage(
actionButton('insertBtn', 'Insert'),
actionButton('removeBtn', 'Remove'),
verbatimTextOutput("summary"),
tags$div(id = 'placeholder')
)
server <- function(input, output, session) {
## keep track of elements inserted and not yet removed
inserted <- c()
observeEvent(input$insertBtn, {
btn <- input$insertBtn
id <- paste0('txt', btn)
insertUI(
selector = '#placeholder',
## wrap element in a div with id for ease of removal
ui = tags$div(
actionButton(inputId = paste0("truc",id),label = paste0("truc",id)),
id = id
)
)
inserted <<- c(id, inserted)
})
observeEvent(input$removeBtn, {
removeUI(
## pass in appropriate div id
selector = paste0('#', inserted[length(inserted)])
)
inserted <<- inserted[-length(inserted)]
})
output$summary <- renderPrint({
invalidateLater(1000)
lst <- reactiveValuesToList(input)
message("upd")
lst[order(names(lst))]
})
}
shinyApp(ui, server)
Any idea how to do this ?