Hi all,
I'm trying to implement bindCache
to make my shiny app faster. There is a long running data query that sometimes fails. I am using validate(need(..))
to check to see if it fails and wait, but bindCache
still seems to write. This means if I want to try it again, the cache kicks in with the error message from the need(). Is there a better workflow for this to let the app try again if there's an error? Or alternatively, can I invalidate the cache easily for a particular key? A dummy example of bindCache
still writing with need
is below.
library(shiny)
library(tidyverse)
shinyOptions(cache = cachem::cache_disk("cache"), max_age = 60 * 60 * 24)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
validate(
need(1 == 2, 'hmm')
)
print("hi")
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
}) %>% bindCache(input$bins)
}
# Run the application
shinyApp(ui = ui, server = server)
Created on 2021-06-14 by the reprex package (v2.0.0)