【问题标题】:Can I let Shiny wait for a longer time for numericInput before updating?我可以让 Shiny 在更新之前为 numericInput 等待更长的时间吗?
【发布时间】:2016-04-28 12:31:08
【问题描述】:

在我的 Shiny App 中,有几个 numericInputselectInput

在输入过程中闪亮更新输出,尤其是当用户在 numericInput 中输入速度较慢时。

sumbitButton 可以用来停止自动更新吗?但我宁愿不使用它。

我怎么能让Shiny为numericInput等待更长的时间?

感谢您的任何建议。如果我的问题不清楚,请告诉我。

【问题讨论】:

  • 您可以通过添加更新输出的“提交”等操作按钮来实现。
  • 感谢您的建议。我更喜欢不使用 submitButton。更新我的问题以进行澄清。
  • 目前还没有很简单的方法可以做到这一点。它涉及操纵闪亮使用的javascript。不过这其实是前两天闪亮的开发者说要加的功能,大家可以关注here

标签: r shiny


【解决方案1】:

您可以在使用您的输入的反应函数上使用debounce。 将其设置为 2000 毫秒对我来说感觉不错。 如果您直接在渲染函数中使用输入,您可能需要在反应函数中创建要在渲染函数中使用的数据。

这里有一个例子:https://shiny.rstudio.com/reference/shiny/latest/debounce.html

## Only run examples in interactive R sessions
if (interactive()) {
options(device.ask.default = FALSE)

library(shiny)
library(magrittr)

ui <- fluidPage(
  plotOutput("plot", click = clickOpts("hover")),
  helpText("Quickly click on the plot above, while watching the result table below:"),
  tableOutput("result")
)

server <- function(input, output, session) {
  hover <- reactive({
    if (is.null(input$hover))
      list(x = NA, y = NA)
    else
      input$hover
  })
  hover_d <- hover %>% debounce(1000)
  hover_t <- hover %>% throttle(1000)

  output$plot <- renderPlot({
    plot(cars)
  })

  output$result <- renderTable({
    data.frame(
      mode = c("raw", "throttle", "debounce"),
      x = c(hover()$x, hover_t()$x, hover_d()$x),
      y = c(hover()$y, hover_t()$y, hover_d()$y)
    )
  })
}

shinyApp(ui, server)
}

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2010-12-02
    • 1970-01-01
    • 2016-03-17
    • 2021-05-17
    • 2015-07-21
    • 2014-05-02
    • 1970-01-01
    • 2019-07-26
    相关资源
    最近更新 更多