【问题标题】:How to update progress bar when function is running in Shiny App如何在 Shiny App 中运行功能时更新进度条
【发布时间】:2020-05-16 14:33:47
【问题描述】:

我是 Shiny 的新手,我正在为我最近构建的统计模型构建一些非常基本的演示应用程序。

应用程序有一个用于运行模型的数据的 selectInput,一个 “运行模型” 按钮和一个 observerEvent 取决于它。单击它时会出现一个对话框,并显示消息“请稍候...”。但是,由于 te 函数正在运行,因此没有蓝色条填充该框以显示进度。

运行模型的函数在 withProgress() 中,我尝试放置一个 updateProgress(),但我不知道如何让进度条在模型运行时移动,因为该函数不在 for 循环中。

如果您不介意查看完整的 repo,这里是链接 https://github.com/jgpeniche/Bayesian_T_TIIE.git

我所指的应用程序中的代码块如下:

服务器

server <- function(input, output) {

    observeEvent(input$run, {
        # wrap the loop execution in withProgress
        withProgress(

            message='Please wait',
            detail='Running Model...',
            value=0, {

                # Some code lines

                # Some function that takes really long time to run

                rnorm(1000000000, 0,1)
                updateProgress()
        })
})

})



【问题讨论】:

  • 要使 StackOverflow 正常工作,您需要提出具体的问题,并提供任何人都可以通过几条命令重现的示例。所以。不擅长在整个互联网上提出一个开放式问题。 KISS = 保持简单...
  • 感谢@oaxcamatt,希望编辑解决了 KIS 评论

标签: r ggplot2 shiny shiny-reactivity shinyapps


【解决方案1】:

您想使用incProgress() 增量更新进度条。

server <- function(input, output) {

observeEvent(input$run, {
    # wrap the loop execution in withProgress
    withProgress(

        message='Please wait',
        detail='Running Model...',
        value=0, {
            n <- 4
            # Some code lines

            # Some function that takes really long time to run

            rnorm(1000000000, 0,1)
            incProgress(1/n, detail = paste("Finished section 1"))

            #more lines of code

            incProgress(1/n, detail = paste("Finished section 2"))
    })
})

})

【讨论】:

    猜你喜欢
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多