【问题标题】:R Shiny showModal and removeModal for all users所有用户的 R Shiny showModal 和 removeModal
【发布时间】:2017-11-23 04:53:01
【问题描述】:

我的一般问题是,我希望在所有用户输入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()
    } 
})

【问题讨论】:

  • 如何更新Class$Ready的值?

标签: r shiny


【解决方案1】:

你也许可以做这样的事情。我打印出会话数以查看已连接的会话数:

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)

【讨论】:

  • 感谢您的回复。看来问题是我还想在 showModal 命令之后重置这些值。我已编辑问题以反映这一点。
猜你喜欢
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-15
  • 2017-05-06
  • 2018-11-09
相关资源
最近更新 更多