Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay on sliderinput

Is there a way to make the sliderInput wait for a couple seconds before it changes its corresponding input$ variable? I have a bar that is controlling a graph that needs to re-render upon the value change. I'm aware of the workaround with a submit button, I'm looking to avoid needing that.

like image 473
hedgedandlevered Avatar asked Aug 26 '15 19:08

hedgedandlevered


1 Answers

debounce is made for this, and is simpler. Modifying previous answerer's code:

library(shiny)
library(magrittr)
shinyApp(
  server = function(input, output, session) {
      d_mean <- reactive({
        input$mean
      }) %>% debounce(1000)
      output$plot <- renderPlot({
          x <- rnorm(n=1000, mean=d_mean(), sd=1)
          plot(density(x))
      })
  },
  ui = fluidPage(
    sliderInput("mean", "Mean:", min = -5, max = 5, value = 0, step= 0.1),
    plotOutput("plot")
  )
)
like image 120
tresbot Avatar answered Sep 19 '22 04:09

tresbot