【问题标题】:What is the execution order inside shiny observeEvent()?闪亮的observeEvent()中的执行顺序是什么?
【发布时间】:2018-03-07 21:03:33
【问题描述】:

我想点击一个按钮,触发 insertUI,计算一些东西,最后 removeUI。但是insertUI/removeUI在计算之后才生效。

我正在按照官方的例子来动态更新 UI。 https://shiny.rstudio.com/articles/dynamic-ui.html

在 removeUI 之后添加 Sys.sleep(2) 时,似乎是在删除元素之前执行的。

ui <- fluidPage(
  actionButton("rmv", "Remove UI"),
  textInput("txt", "This is no longer useful")
)

server <- function(input, output, session) {
  observeEvent(input$rmv, {
    removeUI(
      selector = "div:has(> #txt)"
    )
    Sys.sleep(2)
  })
}

shinyApp(ui, server)

这是什么原因,如何解决?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可能正在寻找 immediate 参数。

    removeUI(selector = "div:has(> #txt)", immediate = TRUE)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      相关资源
      最近更新 更多