Best practices with Shiny for accessing routinely-updated external files?



I have created Dashboard in Rshiny using Google Analytics data and published the App. Now, daily Rscript runs and extract yesterday's data from Google Analytics and stored into .Rds file. The issue I have observed here is that the updated data is not reflecting on a published dashboard automatically. If I restart the shiny-server then only I am able to see updated data.

What could be the cause of this issue? How to handle this?

Thank You!


You have a few options here, depending on where and how you read the .Rds file.

If you call readRDS in global.R, or at the top of server.R (outside of the server function itself), then the Rds file is only read at application start time. Many sessions may come and go, but these will not cause the file to be re-read. This can be good, if you expect the data to never change, because you're not wasting time re-reading the same data over and over.

If you call readRDS inside the server function (but not in a reactive expression or rendering function, just directly inside the server function) then the Rds file is read at session start time. Then the file will be re-read just by hitting Reload in your browser.

Maybe the best option is using reactiveFileReader instead of readRDS, do this either in global.R or at the top of server.R. This will repeatedly check the timestamp of the Rds file, and when it detects a modification, then it'll trigger reactivity. In this case you don't even need to refresh any sessions; all of your live sessions will immediately update in realtime.


A post was split to a new topic: Error in $: object of type 'closure' is not subsettable