r - 我可以让 Shiny 在更新之前等待更长时间的 numericInput 吗?

标签 r shiny

在我的 Shiny App 中,有几个 numericInputselectInput .

Shiny 在打字期间更新输出,尤其是当用户在 numericInput 中打字较慢时。
sumbitButton你能不能用来停止自动更新。但我宁愿不使用它。

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

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

最佳答案

您可以使用 debounce在使用您的输入的 react 函数上。
将它设置为 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)
}

关于r - 我可以让 Shiny 在更新之前等待更长时间的 numericInput 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34937698/

相关文章:

r - 如何绘制具有显着水平的箱线图?

重复测量,格式困惑,需要帮助整理

python - 等效于 Python pandas 中的 'mutate_at' dplyr 函数

r - 使用 googlesheets4 通过 R 中的 Shiny 连接到 googlesheets

R 循环太长

r - 如何将总和添加到表格中并获得 R 中每个单元格的比例

R Shiny DataTable 动态行选择与过滤数据

r - 热图颜色在绘图中不起作用

R Shiny : Use Onclick Option of Actionbutton on the Server Side

r - 使用 rCharts、shiny、nPlot 在 nvd3 中关闭散点图上的放大