2017-12-05 6 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

두 개의 옵션을 추가했습니다. 하나는 알아두면 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)