How to cache data in shiny server?

Viewed 4536

I am using R to deploy an app over the web, but the URL from which my app takes data is where my app takes time. Is it possible to cache that data? I tried to install the packages memoise, R.cache and a few more that were all unsupported by the server.

2 Answers

This article from Rstudio is quite exhaustive and walks you through different ways to achieve that (i.e diskcache, the storr package or a Redis instance).

The main logic revolves around rendering a cached element and setting up the logic for cache invalidation:

function(input, output) {
  renderCachedPlot(
    {
      # Code for a beautiful plot
    },
    # A change in the input or the dataframe will invalidate the cache
    cacheKeyExpr = list({ input$n, df() }) 
  )
}
Related