I have my Shiny App which works fine, but I would like to add a functionality that counts the application inactivity time and closes the application after the set time is exceeded.
It is easy to close an application using the stopApp() function, but how to check the application inactivity time?
I have no idea how to do this, does anyone have any ideas? I will be grateful for your help :)
EDIT:
The solutions proposed by Mwavu and Judy below works fine, but not perfectly as I would like, there is one case that this solution does not handle - a long process in the application, the result of which the user is waiting for. In this case, if the process lasts longer than the inactivity limit, the application will not close during the process because the session is blocked, but will do so immediately after it is released. I would like this process to be treated as "application activity" and only after its completion, instead of killing the application, the inactivity time should be counted from scratch.
The Shiny
invalidateLater()function will help you accomplish this. It reacts or re-executes when the specified number of milliseconds has passed. Since you are also interested not in just the passage of time, but the time since the last user interaction with the Shiny app, you'll need another reactive variable that updates when a user takes an action. Here's a small example:Note that every time you click the checkbox or the plot re-renders due to user interaction with the slider, the time since user activity resets to 0. Once the app has been idle the specified length of time, it closes.
Edit: If your application includes functions with long computation times, you don't want the application to timeout due to that delay. You must either:
processorBusy(TRUE)before long computation and back toprocessorBusy(FALSE)after computation completemaxIdleMinsto be LONGER than the maximum time you expect your computation to take