我知道我可以像这样将 debounce 与reactive() 结合使用,这就是我需要的行为,但我想改用reactiveValues() 。
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)
}
但我更喜欢使用reactiveValues()而不是reactive()。
有什么方法可以将 debounce 与reactiveValues()一起使用吗?
这不起作用:
ui <- fluidPage(
textInput(inputId = "text",
label = "To see how quickly..."),
textOutput(outputId = "text")
)
server <- function(input, output, session) {
values <- reactiveValues()
observe({
values$text= function(x)input$text
values$t <-
debounce(values$text(),2000)
})
output$text <- renderText({
values$t()
})
}
shinyApp(ui, server)
我收到一个错误Warning: Error in r: could not find function "r"
,我猜是因为values
不是反应式表达吗?