session_lifetime

session_lifetime function

Give widgets constructed inside this block the lifetime of the Shiny session rather than of the current render.

Usage Source

session_lifetime()

Widgets constructed while an output renders are closed when that render is invalidated. Construct a widget inside session_lifetime() when you intend to display it again in a later render (for example, one cached widget per dataset). Exiting the block closes nothing; session widgets are closed when the session ends.

A background task started during a render keeps that render’s lifetime: if the task is meant to outlive its render (for example, one streaming updates into a map), construct its widgets inside session_lifetime(), or they are closed when the render that started the task is invalidated.