我的一般问题是,我希望所有用户都输入enter
按钮后显示一个模式窗口,然后在所有用户单击actionButton
后关闭。
我真的很喜欢这样的命令removeModal(domain="Everyone")
和showModal(domain="Everyone")
我的方法是填充 vector 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()
}
})
最佳答案
您也许可以做这样的事情。我打印出 session 数以查看已连接的 session 数:
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)
关于r - R面向所有用户的Shiny showModal和removeModal,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47447795/