How to cache data in shiny server?

后端 未结 2 1311
野性不改
野性不改 2020-12-17 03:10

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 pa

2条回答
  •  执念已碎
    2020-12-17 03:36

    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() }) 
      )
    }
    

提交回复
热议问题