从下面的示例中,我希望用户输入的显示仅每 2 秒(2000 毫秒)更新一次。但事实并非如此,它的更新速度与我不包含 debounce 语句时一样快。
if (interactive()) {
options(device.ask.default = FALSE)
ui <- fluidPage(
textInput(inputId = "text",
label = "To see how quickly..."),
textOutput(outputId = "text")
)
server <- function(input, output, session) {
text_input <- reactive({
input$text
})
debounce(text_input, 2000)
output$text <- renderText({
text_input()
})
}
shinyApp(ui, server)
}
Run Code Online (Sandbox Code Playgroud)
您必须分配debounce()调用结果并在输出中使用它:
server <- function(input, output, session) {
text_input <- reactive({
input$text
})
text_d <- debounce(text_input, 2000)
output$text <- renderText({
text_d()
})
}
Run Code Online (Sandbox Code Playgroud)