Skip to content

Instantly share code, notes, and snippets.

@dokato
Created September 14, 2019 13:43
Show Gist options
  • Save dokato/7c0e7717b732d1aa6574687ff6125f64 to your computer and use it in GitHub Desktop.
Save dokato/7c0e7717b732d1aa6574687ff6125f64 to your computer and use it in GitHub Desktop.
delayed checkbox
library(shiny)
library(magrittr)
library(ggplot2)
ui <- fluidPage(
checkboxGroupInput("checkbox", "Variables to show:",
c("psavert", "uempmed", "unemploy")),
plotOutput("plot")
)
server <- function(input, output, session) {
checkbox <- reactive({
input$checkbox
})
checkbox_delayed <- checkbox %>% debounce(1000)
output$plot <- renderPlot({
p <- ggplot(economics, aes(x = date))
lapply(checkbox_delayed(), function(z) {p <<- p + geom_line(aes_string(y = z)) })
p
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment