How can I use a modalDialog inside a loop? I've looked at some forums but none of them were satisfactory or didn't fit my problem.
Below is a minimal reproducible code that simulates my problem. The solution presented in RShiny: How to have sequential Modals in for loop didn't work as the actionbutton I put in the text argument of the shinyalert function was not recognized in the observeEvent.
library(shiny)
dialog_filtro <- function(ID,LabelID,messagee){
modalDialog(
title = "Menssagem importante",
messagee,
footer = tagList(
actionButton(ID[1],LabelID[1]),
actionButton(ID[2],LabelID[2])
)
)
}
ui <- fluidPage(
uiOutput('res')
)
server <- function(input, output, session) {
RESFIL <- reactiveValues(dest = NULL)
lista <- list(a=2,a=3)
grupdest <- rep(list(NA),length(lista))
RESFIL$dest <- grupdest
for(i in 1:length(lista)){
if(lista[[i]] > 0){
showModal(dialog_filtro(ID = c(paste0('yes',i),paste0('no',i)),
LabelID = c('Yes','No'),
messagee = paste0('This is the loop ',i)
))
observeEvent(input[[paste0('yes',i)]], {
RESFIL$dest[[i]] <- i+10
removeModal()
})
observeEvent(input[[paste0('no',i)]], {
RESFIL$dest[[i]] <- i+100
removeModal()
})
}else{
RESFIL$dest[[i]] <- i+1000
removeModal()
}
}
output$res <- renderPrint({ RESFIL$dest })
}
shinyApp(ui = ui, server = server)