Widgets
Widgets can be used to create transforms that users can update based on user input. You’re able to define a widget and use its user input in your analysis code.
Each widget functions as a Python class and can be assigned to a variable. By calling .value
on the variable, you can access the actual widget value. For example:
Widgets are rendered in the order that they are called.
Supported Widget Types
Below is a comprehensive list of supported widget types.
Widget Appearance
Each widget allows you to specify appearance and input discriptions.
appearance
: a dict containing widget appearance attributes:
"placeholder"
: placeholder value displayed before a set value
"detail"
: secondary label text displayed after thet label
"help_text"
: informative text displayed below input
"error_text"
: error text displayed below input that replaceshelp_text
and sets the input state as errored
"description"
: longer description text displayed in a hoverable tooltip next to the label
Widgets Reactivity
Widgets are reactive, meaning that they automatically update in response to changes in upstream widgets they depend on. In other words, the downstream data transformation will just run, without you having to click the “Run” button explicitly.
For instance, consider a scenario where you use a file selector widget to load a file. If you have a subsequent dropdown widget designed to display values from a specific column in that file, it will dynamically update its list of options whenever the file in the file selector widget changes. This reactive behavior ensures that the widgets remain synchronized and relevant to the current data context.
Example:
Important: To enforce the reactive behavior, observe how csv.value
is
used in the second data transformation block, rather than in the initial
block. This setup is crucial because it allows changes in csv.value
to
trigger the automatic execution of the subsequent data transformation cell.
Can I access a widget value without triggering a cell rerun?
As mentioned above, you can retrieve a widget value with .value
. Calling .value
inside a cell also causes that cell to re-run automatically when the user input changes for that widget.
For cells with long-running operations, you might want to access a widget’s value without triggering the cell to rerun. You can do this by calling ._signal.sample()
instead of .value
. Think of ._signal.sample()
as capturing a snapshot of the widget’s value at the exact moment you click the “Run” button.
Examples: The following code cell will automatically rerun whenever the widget value changes:
The following code will only execute when the user presses the “Run” button in the UI:
Was this page helpful?