【问题标题】:Shiny progress bar completed before do.call() is terminated在 do.call() 终止之前完成的闪亮进度条
【发布时间】:2017-12-05 15:12:32
【问题描述】:

我正在尝试实现一个闪亮的应用程序,它使用一组参数调用一个函数。这样的函数返回一个用 renderPlot() 渲染的图。会生成一个进度条来让用户保持更新。

我对使用do.call 调用这个函数及其参数特别感兴趣,因为我的最终目标是将它包装成一个闪亮的模块。但是,在有机会生成情节之前,进度条已“完成”。只有在进度条消失后,绘图才会被渲染。我认为这是由于我试图使用do.call() 来处理绘图功能。我在这里创建了问题的简化版本:

ui <- fixedPage(
  wellPanel(
    plotOutput("plot")
    , fluidPage(actionButton("Btn", "plot", class = "btn-primary"))
  )
)

server <- function(input, output, session) {

  observeEvent(input$Btn, {

    message("button triggered")

    withProgress(message = "Progress bar"
                   , detail ='Rendering plot...'
                   , value = 0,{

                     # pausa
                     Sys.sleep(1)               
                     # updade progress bar
                     setProgress(0.5)

                     output$plot <- renderPlot({
                       # plot to render
                       do.call(plot, list(1:10, 11:20))  
                       # pause
                       do.call(Sys.sleep, list(2))
                     })

                     # update progress to complete status
                     setProgress(1)
                   })



    showNotification("DONE!", duration = 5, closeButton =  TRUE, type = "warning")

  })
}

shinyApp(ui, server)

我希望在情节生成和可视化后完成进度条。有什么建议吗?

【问题讨论】:

    标签: r progress-bar shiny do.call


    【解决方案1】:

    我添加了两个选项,一个是 shinycssloaders,如果您不知道,另一个是修复您现有的代码以同步绘图和条形图。

    library(shinycssloaders)
    
    ui <- fixedPage(
      wellPanel(
        #withSpinner(plotOutput("plot")) #uncomment if you need to use the pkg
        plotOutput("plot")
        , fluidPage(actionButton("Btn", "plot", class = "btn-primary"))
      )
    )
    
    server <- function(input, output, session) {
    
      observeEvent(input$Btn, {
    
        message("button triggered")
    
        withProgress(message = "Progress bar"
                     , detail ='Rendering plot...'
                     , value = 0,{
    
                       # pausa
                       Sys.sleep(1)               
                       # updade progress bar
                       setProgress(0.5)
    
    
    
                       # update progress to complete status
                       setProgress(1)
                     })
    
        output$plot <- renderPlot({
          # plot to render
          do.call(plot, list(1:10, 11:20))  
          # pause
          #do.call(Sys.sleep, list(2))
        })
    
    
        showNotification("DONE!", duration = 5, closeButton =  TRUE, type = "warning")
    
      })
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2016-01-12
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 2018-05-29
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      相关资源
      最近更新 更多