Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand how debounce works

Tags:

r

shiny

From the example below, I would expect the display of user input to only update every 2s (2000ms). But it's not, it's updating just as fast as when I don't include a debounce statement.

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)
}
like image 968
Ploulack Avatar asked Jan 03 '23 05:01

Ploulack


1 Answers

You have to assign the result of the debounce() call and use that in your output:

server <- function(input, output, session) {
    text_input <- reactive({
        input$text
    })

    text_d <- debounce(text_input, 2000)

    output$text <- renderText({
        text_d()
    })
}
like image 83
Marius Avatar answered Jan 18 '23 00:01

Marius