My general problem is that I would like a modal window to show up after all users have entered an enter button then close after all users click actionButton.
I'd really love commands like
removeModal(domain="Everyone") and showModal(domain="Everyone")
My approach is to fill a vector Class$Ready until all values are TRUE and then create the window. Based on the commentors, I can get shiny to display a modal window on all users pages once that condition is satisfied. But I cannot remove it for all users.
server.R
## Global Variables
Class <<- data.frame(ID=1:10, Ready=rep(FALSE,10) )
GlobClass <<- reactiveValues(Ready=Class$Ready, New=Class$Ready) )
## When Enter is Clicked, Update
observeEvent( input$enter, {
GlobClass$Ready[ Class$ID == user] <- TRUE
})
## When Everyone has clicked enter, showModal
observeEvent (GlobClass$Ready, {
if( all(GlobClass$Ready) ){
showModal( modalDialog(
h2("Effort"), "Try Harder",
footer=tagList( actionButton("new", "New Round"))
))
}
})
## When New is Clicked, Update and Hide
observeEvent( input$new, {
GlobClass$New[Class$ID==user] <- TRUE
shinyjs::hide('new')
})
## When Everyone has clicked New, removeModal and reset
observe( { invalidateLater(efreq)
if( all(GlobClass$New) ){
GlobClass$Ready <- rep(FALSE, nrow(Class))
GlobClass$New <- rep(FALSE, nrow(Class))
removeModal()
}
})
The issue I'm having is that the modalWindow is only removed for one person not all. That's also true if I change observe( { invalidateLater(efreq)
to observeEvent( GlobClass$New, {
Edit: Answer
You have to stagger the calls
observeEvent( GlobClass$New, {
#observe( { invalidateLater(efreq)
if( all(GlobClass$New) ){
GlobClass$Ready <- rep(FALSE, nrow(Class))
}
})
observeEvent( GlobClass$Ready , {
if( all(!GlobClass$Ready) ){
GlobClass$New <- rep(FALSE, nrow(Class))
removeModal()
}
})
