Generate Widgets from Parameters
This guide addresses how to generate UIs from Parameterized classes without writing any GUI related code.
Parameters are Python attributes extended using the Param library to support types, ranges, and documentation, which turns out to be just the information you need to automatically create widgets for each parameter.
Declaring and displaying parameters
Internally parameters have a mapping that generates widgets appropriate for each type. This means that by declaring a Parameterized
class we can automatically generate a full UI. Let us declare a BaseClass
:
and then render the resulting UI using Panel:
By changing a widget and re-running the following outputs, we can see that changes in the widgets are automatically reflected in Python:
The reverse is also true; editing a parameter from Python will automatically update any widgets that were generated from the parameter:
Passing the .param
object renders the full set of widgets, while passing a single parameter will display just one widget. In this way we can easily declare exactly which parameters to display:
Advanced parameters
The BaseClass
primarily declared simple parameters, however there are a wide range of parameter types covering many use cases. Below we define a subclass with some of these additional parameter types.
For example, the Example.timestamps
Parameter records the timestamps from every "record timestamp" button press above. Rerun the code block below after clicking the button in order to see the output in the docs.
Related Resources
See the Explanation > APIs for context on this and other Panel APIs