Python/Shiny Long Running Dashboards - Memory Leaks In Server and Client

If you must support user sessions that last this long for an application like this, I would recommend forcing a refresh of the page after a certain period of time, which should cap the memory usage.

Here a snippet of JavaScript to do that

// After 10 minutes of inactivity, refresh the page
const INACTIVITY_TIMEOUT = 10 * 60 * 1000;

function setupAutoReload() {

    const reloadPage = () => {
        console.log('No activity detected for 10 minutes. Reloading...');
        window.location.reload();
    };

    // Track the inactivity timeout
    let inactivityTimer = null;

    // When the user interacts with the page, reset the inactivity timer
    const handleActivity = () => {
        if (inactivityTimer) {
            clearTimeout(inactivityTimer);
        }
        inactivityTimer = setTimeout(reloadPage, INACTIVITY_TIMEOUT);
    };

    // A list of events that should reset the inactivity timer
    const events = ['mousemove', 'mousedown', 'keypress', 'scroll', 'touchstart', 'resize', 'click', 'keydown', 'wheel'];

    events.forEach(eventType => {
        window.addEventListener(eventType, handleActivity, { passive: true });
    });

    // Set initial timer
    inactivityTimer = setTimeout(reloadPage, INACTIVITY_TIMEOUT);
}

// Initialize the auto-reload functionality
// Important: only call this once
setupAutoReload();

To include the JavaScript in your app, you can include it in a ui.tags.script() (like you've have in the original example app).