How to group settings within a panel

I have built a complex control system for a scientific instrument. Settings are implemented as Param objects, with one Parameterized class for each component of the instrument. Settings are displayed in a UI using Panel, which serialises and sends settings to the instrument.

Some components now have dozens of settings and I would like to make the UI easier to use by grouping the settings for one component into UI group-boxes, or sections with titles, or into an accordion.

I know I can use precedence to order the settings. I know I could break each component’s settings into multiple child Parameterized objects, but this would be a huge change and would give me other problems with my custom serialisation.

I found that I could add any Python object to a Parameterized, so I added a dictionary of groups. I then tried to add the settings in each group to the UI, but this didn’t work because that subset of settings was not a Parameterized.

I also tried adding all the settings multiple times to the UI, each time setting the precedence to -1 for those that were hidden in each group. But this just showed only the last group, because the precedence was being overwritten each time.

Please does anyone know of a way to group the settings in a Parameterized class in the UI, without breaking it into a hierarchy of settings?

1 Like

Can you share a bit of code as to how you’re currently doing it?

I’m not currently doing it, because I can’t find a way that works. Hence the question…!

Hi @richardwhitehead

What I we need is some code to start from to understand you specific challenges. What you describe in text can mean so many things.

For example I interpret what you write as

import panel as pn
import param

pn.extension()


class Component(pn.viewable.Viewer):
    setting1 = param.String()
    setting2 = param.String()

    def __panel__(self):
        return pn.Param(self)


class ControlSystem(pn.viewable.Viewer):
    component1 = param.ClassSelector(class_=Component)
    component2 = param.ClassSelector(class_=Component)

    def __panel__(self):
        return pn.Param(self)

    def __init__(self, **params):
        super().__init__(**params)
        self.component1 = Component(name="Component 1")
        self.component2 = Component(name="Component 2")


ControlSystem().servable()

Which looks like

This is not so great. So I believe you are asking how to make this look and feel better. Especially as the number of controls and settings start growing?

Is that correct?