Create nested UIs
This guide addresses how to structure Parameterized
classes with subobjects to create nested UIs automatically.
Parameterized
objects often have parameter values which are themselves Parameterized
objects, forming a tree-like structure. Panel allows you to edit not just the main object's parameters but also lets you drill down to the subobject. Let us first define some classes declaring a hierarchy of Shape classes which draw a Bokeh plot of the selected shape:
Now that we have multiple Shape classes we can make instances of them and declare a ShapeViewer
to select between them. We can also declare two methods with parameter dependencies, updating the plot and the plot title. The important thing to note here is that the param.depends
decorator can not only depend on parameters on the object itself but also on specific parameters on the subobject, e.g. shape.radius
, or on all parameters of the subobject, expressed as shape.param
.
Now that we have a class with subobjects we can display it as usual. Three main options control how the subobject is rendered:
expand
: Whether the subobject is expanded on initialization (default=False
).expand_button
: Whether there should be a button to toggle expansion; otherwise it is fixed to the initialexpand
value (default=True
).expand_layout
: A layout type or instance to expand the plot into (default=Column
).
Let us start with the default view, which provides a toggle button to expand the subobject as desired:
Alternatively we can provide a completely separate expand_layout
instance to the Param pane and request that it always remains expanded using the expand
and expand_button
option. This allows us to lay out the main widgets and the subobject's widgets separately:
Related Resources
See the Explanation > APIs for context on this and other Panel APIs