Instantly share code, notes, and snippets.

Embed
What would you like to do?
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