Shiny - 如何在流程完成时告诉客户

Shiny - How to tell client when a process is done

我是 Shiny 的新手,我无法在需要时呈现 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)))
})

文本未显示 "Processing...",而 #SomeCodeHere 是 运行。我真的不明白为什么。应该不行吗?

仅在 observeEvent 完成后呈现文本。我知道这一点,因为如果我删除 SECOND renderText(),当处理结束时,文本将采用值 "Processing..."。

如果这是正常行为,有没有办法在 observeEvent 结束之前强制渲染?

编辑:

还有其他(任何)方法可以实现我想要的吗?

张贴我的评论作为答案(谢谢!)

关于进度条的文章是here and the reference 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)
     )
   })
 })

虽然这与您的问题无关,但我注意到您在 observeEvent 中放置了一个 output,并用一些 isolate 包裹了 inputs

一位闪亮的开发人员在 first two videos of shiny's 2016 conference 中谈论观察者。它帮助我更好地理解了如何使用观察者,我想你可能会发现它很有用。 :]