闪亮的进度栏不适用于mclapply()

时间:2019-07-08 20:03:39

标签: r shiny progress-bar shiny-server

incProgress()放在mclapply()中时,shiny的默认进度栏似乎没有更新。下面是一个示例

library(shiny)
library(parallel)

ui <- fluidPage(
  plotOutput("plot")
)

server <- function(input, output) {
  output$plot <- renderPlot({
    withProgress(message = 'Calculation in progress',
                 detail = 'This may take a while...', value = 0, {
      mclapply(1:15, function(i) {
        incProgress(1/15)
        Sys.sleep(0.25); flush.console()
        return(NULL)
      }, mc.cores = 2)

    })
    plot(cars)
  })
}

shinyApp(ui, server)
}

但是,当我使用lapply()时,它可以正确显示进度。

是否有任何黑客可以在mclapply()上使用Shiny的进度栏?

系统信息:

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] C/UTF-8/C/C/C/C

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] shiny_1.2.0

loaded via a namespace (and not attached):
 [1] compiler_3.5.2  magrittr_1.5    R6_2.4.0        promises_1.0.1 
 [5] later_0.8.0     tools_3.5.2     htmltools_0.3.6 Rcpp_1.0.0     
 [9] jsonlite_1.6    digest_0.6.18   xtable_1.8-3    httpuv_1.4.5.1 
[13] mime_0.6        rlang_0.3.1    

0 个答案:

没有答案