Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.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
R 在do.call()终止之前,进度条已完成_R_Progress Bar_Shiny_Do.call - Fatal编程技术网

R 在do.call()终止之前,进度条已完成

R 在do.call()终止之前,进度条已完成,r,progress-bar,shiny,do.call,R,Progress Bar,Shiny,Do.call,我正在尝试实现一个闪亮的应用程序,它使用一组参数调用函数。此函数返回使用renderPlot()呈现的绘图。将生成一个进度条,以保持用户的更新 我特别感兴趣的是使用do.call调用这个函数及其参数,因为我的最终目标是将它包装成一个闪亮的模块。但是,在绘图有机会生成之前,进度条已“完成”。只有在进度条消失后,才会渲染打印。我假设这是因为我试图使用do.call()来处理绘图函数。我在这里创建了问题的简化版本: ui <- fixedPage( wellPanel( plotOu

我正在尝试实现一个闪亮的应用程序,它使用一组参数调用函数。此函数返回使用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)

ui我添加了两个选项,一个是使用
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)
库(shinycssloaders)
用户界面