My problem with breaking a loop insidse shinyalert has been solved in this post.
I decided to try "Chaining modals" approach.
The approach seems to work in my case, hovewer I am facing another problem-
as I am not using any loop, values are not used as a parameter anymore (vector "all.elements" is not being used).
In my case it is a little bit a problem, because in my original app "elements" to be checked are being selected beforewards and only a part of vector elements should be included in "shinyalert" part.
For this reason I would like to keep "vector of elements" with elements selected beforewards. Elements not included in the vector should be skipped in the chain of modals (in the example element "C" should be skipped, that means "Do you accept element C?" message should not pop up even if elements "A" and "B" had been previously confirmed by a user).
App should proceed from "Do you accept element B?" to "Do you accept element D?" question directly
I was trying to achieve that using ifelse function inside my shinyalert but I have not succeeded.
Is there way to do that? Below the code I wrote using "Chaining modals" approach.
library(shiny)
library(shinyalert)
ui <- fluidPage(
actionButton("run", "Run")
)
server <- function(input, output, session) {
observeEvent(input$run, {
all.elements <- c("A", "B", "C", "D", "E")
selected.elements <- c("A", "B", "D", "E")
shinyalert(
title = "Do you accept element A?",
showCancelButton = TRUE,
callbackR = function(value) {
ifelse(value == TRUE,
shinyalert(title = "Do you accept element B?",
showCancelButton = TRUE,
callbackR = function(value) {
ifelse(value == TRUE, shinyalert(title = "Do you accept element C?",
showCancelButton = TRUE,
callbackR = function(value) {
ifelse(value == TRUE, shinyalert(title = "Do you accept element D?",
showCancelButton = TRUE, callbackR = function(value) {
ifelse(value == TRUE,
shinyalert(title = "Do you accept element E?",
showCancelButton = TRUE), decision <<- "STOP")}), decision <<- "STOP")}), decision <<- "STOP")}), decision <<- "STOP")}
)
})
}
shinyApp(ui = ui, server = server)
Another thing I noticed, when I click "OK" quickly, sometimes the consecutive message does not appear. Maybe there is a way to do similar thing using Modals approach built in Shiny, without using the shinyalert library?