【问题标题】:Shiny - How to tell client when a process is doneShiny - 如何在流程完成时告诉客户
【发布时间】:2016-10-10 17:24:48
【问题描述】:

我对 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)))
})

#SomeCodeHere 正在运行时,文本未显示“正在处理...”。我真的不明白为什么。它不应该工作吗?

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

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

编辑:

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

【问题讨论】:

标签: r text shiny render observers


【解决方案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)
     )
   })
 })

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-04
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多