Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Created November 9, 2018 16:32
Show Gist options
  • Save jcheng5/1f09a0939ae45fd36f286a158bcb0dfb to your computer and use it in GitHub Desktop.
Save jcheng5/1f09a0939ae45fd36f286a158bcb0dfb to your computer and use it in GitHub Desktop.
Simple Shiny app, with and without plot caching
library(ggplot2)
library(shiny)
ui <- fluidPage(
varSelectInput("color_by", "Color by:", diamonds, selected = "cut"),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
ggplot(diamonds, aes(carat, price, color = !!input$color_by)) +
geom_point()
})
}
shinyApp(ui, server)
library(ggplot2)
library(shiny)
shinyOptions(cache = diskCache("plot_cache"))
ui <- fluidPage(
varSelectInput("color_by", "Color by:", diamonds, selected = "cut"),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderCachedPlot({
ggplot(diamonds, aes(carat, price, color = !!input$color_by)) + geom_point()
}, cacheKeyExpr = { input$color_by })
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment