Param Subobjects
This example demonstrates how to use the Param library to express nested hierarchies of classes whose parameters can be edited in a GUI, without tying those classes to Panel or any other GUI framework.
For this purpose we create a hierarchy of three classes that draw Bokeh plots. At the top level there is a ShapeViewer
that allows selecting between different Shape
classes. The Shape classes include a subobject controlling the Style
(i.e. the color
and line_width
) of the drawn shapes.
In each case, param.depends
is used to indicate which parameter that computation depends on, either a parameter of this object (as for radius
below) or a parameter of a subobject (i.e., a parameter of one of this object's parameters, as for style.color
below).
Having defined our basic domain model (of shapes in this case), we can now make a generic viewer using Panel without requiring or encoding information about the underlying domain objects. Here, we define a view
method that will be called whenever any of the possible parameters that a shape might have changes, without necessarily knowing what those are (as for shape.param
below). That way, if someone adds a Line
shape that has no n
parameter but has orientation
, the viewer should continue to work and be responsive. We can also depend on specific parameters (as for shape.radius
) if we wish. Either way, the panel should then reactively update to each of the shape's parameters as they are changed in the browser: