我的一般问题是,我希望在所有用户输入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()
}
})
我遇到的问题是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()
}
})
答案 0 :(得分:5)
你可以这样做。我打印出会话数量以查看有多少会话:
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)