2016-06-09 55 views
0

我是完全新的閃亮,我不能得到一個textOutput呈現當我想要它。閃亮 - 如何告訴客戶當一個過程完成

observeEvent(input$btnPersistencia, { 
    output$txtProtActual <- renderText("PROCESSING...") 
    print("This does print in console") 

    #SomeCodeHere that takes about 10 seconds to finish 

    output$txtProtActual <- renderText(paste("Archivo Persistencia Actual: ", basename(values$file), "\n Dim: ", isolate(input$sliderDimension), "\n Filtr: ", isolate(input$txtMaxFil))) 
}) 

#SomeCodeHere正在運行時,文本沒有顯示「Processing ...」。我真的不明白爲什麼。它不應該工作嗎?

該文本僅在observeEvent完成後呈現。我知道這一點,因爲如果我刪除第二個renderText(),當處理結束時,文本將採用值「Processing ...」。

如果這是正常的行爲,有沒有辦法在observeEvent結束之前強制渲染?

編輯:

是否有另一種(任何)方式來實現我想要的?

+1

也許一個進度條? http://shiny.rstudio.com/articles/progress.html – user5029763

+0

發表你的評論作爲一個完整的答案,我會檢查它作爲正確的答案。這正是我想要的。 –

回答

1

張貼作爲一個答案我的評論(感謝!)

約進度條文章here和參考here。 這裏是你的代碼的進度條:

observeEvent(input$btnPersistencia, { 
    withProgress(message = 'PROCESSING...', value = 0, { 
     incProgress(1/2) 
     #SomeCodeHere that takes about 10 seconds to finish 
     Sys.sleep(10) 
    }) 

    output$txtProtActual <- renderText({ 
    paste("Archivo Persistencia Actual: ", basename(values$file), 
     "\n Dim: ", isolate(input$sliderDimension), 
     "\n Filtr: ", isolate(input$txtMaxFil) 
    ) 
    }) 
}) 

雖然事不關你的問題,我注意到您放置一個outputobserveEvent裏面有一些isolate包裝inputs

其中一個閃亮的開發者談論在first two videos of shiny's 2016 conference觀察員。它幫助我更好地理解如何使用觀察者,並且我認爲您可能會發現它很有用。 :]