I have a shiny app (https://ajackson.shinyapps.io/DisplaySidewalkQuality/) which is rather slow, and could be greatly improved by using debounce, to reduce unneeded redraws. The problem is that I can't seem to grok how to actually use it, given how I have structured the code. I have a simplified reprex below that does not debounce but captures the basic code structure I have used.
#
# Reprex for understanding how to utilize debounce/throttle functionality
#
# Uses Iris data
#
library(shiny)
library(tidyverse)
shinyApp(
ui = basicPage(
titlePanel("Test of debounce"),
# Sidebar with selector for which species
sidebarLayout(
sidebarPanel(
checkboxGroupInput("species", label = "choose species",
choices = list("Setosa"="setosa",
"Versicolor"="versicolor",
"Virginica"="virginica"
),
selected = "")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot1")
)
)
), # basicPage
#####################################################
# Define Server
#####################################################
server <- function(input, output, session) {
##################################
# Make Plot
##################################
draw_plot <- function() {
print(paste("species",input$species))
output$plot1 <- renderPlot({
if (!is.null(input$species)){
iris %>%
filter(Species %in% input$species) %>%
ggplot(aes(x=Petal.Length, y=Petal.Width)) +
geom_point(aes(color=Species))
}
})
}
##################################
# CheckBoxes
##################################
observeEvent(input$species, {
draw_plot()
}, ignoreNULL=FALSE, ignoreInit=TRUE)
}
)