gpt4 book ai didi

R Shiny showModal 和removeModal 适用于所有用户

转载 作者:行者123 更新时间:2023-12-02 09:15:39 25 4
gpt4 key购买 nike

我的一般问题是,我希望在所有用户输入 enter 按钮后显示一个模式窗口,然后在所有用户单击 actionButton 后关闭。

我真的很喜欢这样的命令

removeModal(domain="Everyone")showModal(domain="Everyone")

我的方法是填充向量Class$Ready,直到所有值都为TRUE,然后创建窗口。根据评论者的说法,一旦满足条件,我就可以在所有用户页面上显示模式窗口。但我无法为所有用户删除它。

服务器.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()
}
})

我遇到的问题是 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 数以查看有多少个已连接:

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)

enter image description here

关于R Shiny showModal 和removeModal 适用于所有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47447795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com