session.Inputs.set_snapshot_preprocess

session.Inputs.set_snapshot_preprocess(id, fn)

Set a function for preprocessing an input value in test-mode snapshots.

When a test snapshot is requested (see shiny.testmode), the registered function receives the input's current value and its return value is written to the snapshot instead. Use this to scrub non-deterministic values (timestamps, temp paths, random ids) so snapshots diff cleanly.

The function may be synchronous or asynchronous. It only affects test snapshots – never the live input value. Registering again for the same id overwrites the previous function. Registration is harmless when test mode is off, so calls can be left in production code.

Parameters

id : str

The ID of the input value.

fn : Callable[[Any], Any] | Callable[[Any], Awaitable[Any]]

A function that takes the input value and returns the value to write to the test snapshot.

See Also