我的一般问题是,我希望在所有用户输入enter按钮后显示模态窗口,然后在所有用户单击后关闭actionButton.
我真的很喜欢这样的命令
removeModal(domain="Everyone") 和 showModal(domain="Everyone")
我的方法是填充一个向量,Class$Ready直到所有值都是TRUE,然后创建窗口.基于评论员,一旦满足条件,我就可以在所有用户页面上显示模式窗口.但是我不能为所有用户删除它.
## 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()
}
})
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是modalWindow仅针对一个人而不是全部删除.如果我换observe( { invalidateLater(efreq)
到也是如此 observeEvent( GlobClass$New, {
你必须错开电话
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()
}
})
Run Code Online (Sandbox Code Playgroud)
你也许可以这样做.我打印出会话数量以查看连接数量:
library(shiny)
ui <- fluidPage(
mainPanel(actionButton("Submit","Submit"),textOutput("SessionCount"))
)
vals <- reactiveValues(count=0)
server <- function(input, output, session){
isolate(vals$count <- vals$count + 1)
session$onSessionEnded(function(){
isolate(vals$count <- vals$count - 1)
})
observeEvent(input$Submit,{
if(vals$count !=0){
vals$count <- vals$count - 1
}
},ignoreInit = T)
observeEvent(vals$count,{
if(vals$count ==0){
showModal( modalDialog( h2("Effort"), "Try Harder"))
}
})
output$SessionCount <- renderText({
paste0("Number of Current Sessions: ",vals$count)
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)