Hello!
I need to dynamically generate UI and Module components from a loop, and then Immediately update the Inputs. I'm having issues getting this to work. Any suggestions? In this case, I want the inputs to update to 'Success!!' after I create the UI components.
mdlUI <- function(id){
ns = NS(id)
textInput(inputId = ns("txt"),label = "Did we do it?", value = "Failure....")
}
mdl <- function(input, output, session){
# observeEvent(,{
# updateTextInput(session = session, inputId = "txt", value = "Success!")
# },once = T, ignoreInit = F)
}
ui <- fluidPage(
actionButton("rmv", "Remove UI"),
actionButton("add", "Add UI")
)
server <- function(input, output, session) {
rv.module <- reactiveValues()
observeEvent(input$rmv, {
rv.module <- reactiveValues()
for(i in 1:5){
id <- paste0("mdl",i)
removeUI(
selector = paste0("div:has(> #",id,"-txt)")
)
}
}, ignoreInit = T)
observeEvent(input$add, {
for(i in 1:5){
id <- paste0("module",i)
insertUI(
selector = "#add",
where = "afterEnd",
ui = mdlUI(id)
)
rv.module[[id]] <- callModule(module = mdl, id = id)
}
},ignoreInit = T)
}
shinyApp(ui, server)