Inputs

Inputs(values, ns=Root)

A class representing Shiny input values.

This class provides access to a Session's input values. The input values are reactive Values, and can be accessed with the [] operator, or with .. For example, if there is an input named x, it can be accessed via input["x"]() or input.x().

Methods

Name Description
set_serializer Add a function for serializing an input before bookmarking application state
set_snapshot_preprocess Set a function for preprocessing an input value in test-mode snapshots.

set_serializer

Inputs.set_serializer(id, fn)

Add a function for serializing an input before bookmarking application state

Parameters

id : str

The ID of the input value.

fn : Callable[[Any, Path | None], Awaitable[Any | Unserializable]] | Callable[[Any, Path | None], Any | Unserializable]

A function that takes the input value and returns a modified value. The returned value will be used for bookmarking.

set_snapshot_preprocess

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.