2017-12-05 2 views
1

引数のセットで関数を呼び出す光沢のあるアプリケーションを実装しようとしています。このような関数は、renderPlot()でレンダリングされるプロットを返します。プログレスバーが生成され、ユーザーは更新されたままになります。do.call()が終了する前に光沢のある進捗バーが完了しました

この関数とその引数を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) 

:私はここでの問題の簡易版を作成しました。助言がありますか?

答えて

0

2つのオプションが追加されています.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) 
関連する問題