How can I prevent an R shiny window from "timing out" in a browser?

Viewed 76

I maintain an R package that conducts long-running analyses via a Shiny app. It loads data from a file, conducts an analysis (displaying a progress bar to the user), then displays results.

When I launch the app via RStudio, running in the Google Chrome browser, and leave an analysis running overnight, the script continues to run, displaying regular output in the R terminal. However, when I revisit the Chrome window in the morning, the window displays the app in its initial state (i.e. no evidence that a file has been opened or analyses commenced).

I presume that Chrome is treating the tab as inactive, 'snoozing' it, then re-launching the tab (hence severing the original connection with the R session) when I revisit it.

I'd like the package to be as simple for users to use as possible, so hope to find a solution that doesn't involve fiddling with browser settings (end users may use other browsers too). Is there any way that a Shiny app can be configured to avoid this behaviour?

1 Answers

I faced an alike issue recently. Changing the plot setting values caused blinking and freezing of UI. Investigating into the reasons of such behaviour helped me to find the following way out.

I assume that the major part of processor time is spent to reading the datafile, tidying the data, making analysis and plotting the results. For me the slowest stage was data reading. The way out was to wrap the time-consuming part of code in a separate reactive function. The reactive function result will be calculated only once and the result will be used until the certain required input variables are not changed. So the slow part of code will be skipped and the precalculated result will be ready the further parts of code (plotting for instance). So the code becomes fast enough not to cause delays in UI when making some adjustments (scaling for instance) of plotting.

Related