Widget name should not really be used for label/title

The name attribute of most Widgets is what is used as the display name on the UI. I’ve never seen a UI library/framework where there was no distinction between the name of a UI element and what is displayed on the UI, though I have not seen any questions about it either so I’m guessing this has not been a problem for others.

It is fairly common to use a standard naming convention for mapping UI elements to function event handlers, like on_create_button or create_button_handler. In staticly typed languages, this is just a convention, but with Python one can use the name and a convention for dynamically invoking methods for event handling, except that having all of your UI labels follow python variable naming conventions looks pretty funny.

I can get around this for the eventing use case by doing something like below, but wondering if anyone else has found this to be problematic.

import panel as pn
from functools import partial

ta = pn.widgets.TextAreaInput(name="Some Name")
def eventer(objName, *events):
    for event in events:

ta.param.watch(partial(eventer, "ta"), list(ta.param.values()))

I’m wondering if this lack of distinction is the meat of the issue behind my post here Dynamically update the name of a layout

Basically I want to be able to dynamically change the name displayed on the UI and can’t seem to do so

Yes, I think this is another good example of a problem this causes. Digging into the code, the exact cause of your issue comes from the Param library with the code below showing that the name attribute is set to be a Constant because it is an identifier.

Fundamentally, I think in any UI framework, the identifier of a UI element should always be distinct from what is displayed.

In my case I want to use the identifier as a variable name for dynamic invocation and in your case you want to be able to change the display name.

 class Parameterized(metaclass=ParameterizedMetaclass):
    __Doc String omitted for brevity__
    name = String(default=None, constant=True, doc="""
        String identifier for this object.""")

I also think the way name is implemented and used is fundamentally problematic in many ways. But its been like that for many, many years and I have not seen any appetite from core developers for changing it.

But it would be great in Param 3.0/ Panel 2.0 to get it fixed. But I believe that would require an issue created with Param and a massive amount of upvotes for that issue.

I think there’s definitely appetite for adding a title parameter to Panel components that need one, there must be some issues already about it.

I definitely would like to remove the default name Parameter all Parameterized classes get in Param (see Fate of `name`? · Issue #770 · holoviz/param · GitHub). However it’s a major breaking change, removing it should be done with great care.

1 Like

My thought was to add the functionality without making a breaking change, but everyone on this thread has more knowledge and experience with the Panel and Param libraries.

Something like adding an optional title property to all Panel classes that inherit from Parameterized and using the title instead of name for displaying(though I didn’t track exactly where this happens). If title defaults to the value of name if not provided, this seems to provide a solution that does not break any existing code. It doesn’t address the underlying issue with name in Param, but could provide the functionality until that is resolved in Param.

1 Like