在我的 Shiny App 中,有几个 numericInput
和 selectInput
.
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/