Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pblapply函数的R进度条_R_Progress Bar_Shiny_Lapply - Fatal编程技术网

pblapply函数的R进度条

pblapply函数的R进度条,r,progress-bar,shiny,lapply,R,Progress Bar,Shiny,Lapply,有没有办法在pblappy函数中插入闪亮进度函数(incProgress),以便在右上角以百分比的形式显示进度。每次lappy函数再次启动时,都需要对IncProgress(…)进行评估,就像在基于文本的进度栏中更新控制台一样 下面是我的测试示例: runApp(list( ui = shinyUI( fluidPage( actionButton("calc","Start calculation"), dataTableOutput("out") ) ), server =

有没有办法在pblappy函数中插入闪亮进度函数(incProgress),以便在右上角以百分比的形式显示进度。每次lappy函数再次启动时,都需要对IncProgress(…)进行评估,就像在基于文本的进度栏中更新控制台一样

下面是我的测试示例:

runApp(list(
 ui = shinyUI(
  fluidPage(
  actionButton("calc","Start calculation"),
  dataTableOutput("out")
 )
),
 server = shinyServer(function(session, input, output) {
 library(pbapply)

  #create list
  n <- 100; nn <- 1000
  g <- factor(round(n * runif(n * nn)))
  x <- rnorm(n * nn) + sqrt(as.numeric(g))
  xg <- split(x, g)

  observeEvent(input$calc > 0,{
   withProgress(message = "Initializing data manipulation process", value=0, {
     list = pblapply(xg,mean)
     #insert 'incProgress(percentage, detail = paste0("Progress: ",percentage)' in the pbapply or txtProgress function
  })
   output$out = renderDataTable(datatable(as.data.frame(unlist(list))))
  })
})
)
)
runApp(列表(
ui=shinyUI(
流动摄影(
操作按钮(“计算”、“开始计算”),
dataTableOutput(“输出”)
)
),
服务器=shinyServer(功能(会话、输入、输出){
图书馆(pbapply)
#创建列表

n我不知道您是否可以从
pblappy
中获得百分比,但是您在
中使用progress
可以做到:

percentage <- 0
list = pblapply(xg,function(x) {
          Sys.sleep(0.05); 
          percentage <<- percentage + 1/length(xg)*100
          incProgress(1/length(xg), detail = paste0("Progress: ",round(percentage,2)))
          mean(x); 
})

percentage谢谢,这就解决了问题!一个小小的旁注:incProgress(percentage,…)应该改为incProgress(1/length(xh),…),因为该函数递增地增加了闪亮的进度条。你说得对,不需要
percentage
,我编辑了它。