holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.81k stars 520 forks source link

unique IDs for components #7443

Open hmijail opened 4 weeks ago

hmijail commented 4 weeks ago

Is your feature request related to a problem? Please describe.

Components don't have unique IDs, so it's hard / impossible to refer to them.

Describe the solution you'd like

It probably would be enough to get an unique ID when a component is created in Python. If that is not possible because that happens in the JS part, then at least return some handler so that from Python we can refer to the ID that will be created... or something?

Describe alternatives you've considered

Not a JS/frontend dev, sorry. I tried doing this from Bokeh but looks like they also don't have unique IDs. I'm currently using the xfind project to bruteforcely find what I need. It works, but it's messy: forces me to deal with JS, document loading, etc. Feels like I keep finding corner cases / reverse engineering / patching stuff in the JS side.

Additional context

Follow up to https://github.com/holoviz/panel/issues/6156

mattpap commented 4 weeks ago

Bokeh's components don't have any IDs associated with them by design. If you want to get a view associated with a model (not necessarily UI model), perhaps because you want to get access to its associated DOM element (view.el), then bokehjs provides APIs for that, e.g. Bokeh.index.get_one(model). If you already have a reference to a view of a bokeh model, then you can use view.owner to get access to the global view manager (same as Bokeh.index), or view.views, which will give you access only to descendants of the given view.

hmijail commented 4 weeks ago

Thank you for the information, but... as a non-frontend dev, non-Bokeh user, that went over my head. I'm not sure how it helps.

To contextualize things: as a Python user of Panel, I create 2 Panel HTML panes: A and B. I later need to refer to B. How to do so?

Currently I manually inspect the generated HTML to find an element that is reliably found in B, and later use xfind from the JS side to find this element. But even this won't work when the element is present in both panes.

So my question is:

  1. Can I get some reference to the rendered panes A and B from Python? The goal is to pass their reference to a custom JS script that I am including from Python.
  2. If that's not possible, is there any way to distinguish which of the panes is B once I am in JS?
tfriedel commented 3 weeks ago

having the same question as @hmijail