Repository: holoviz/holoviews

Issue:
Clicking on legend for traces to enable/disable does not work with plotly back end. It does work on Bokeh
Thanks for contacting us! Please read and follow these instructions carefully, then delete this introductory text to keep your issue easy to read. Note that the issue tracker is NOT the place for usage questions and technical assistance; post those at [Discourse](https://discourse.holoviz.org) instead. Issues without the required information below may be closed immediately.


#### ALL software version info
(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)
holoviews 1.15.3
bokeh : 2.4.3
hvplot: 0.8.2
panel: Version: 0.14.1
#### Description of expected behavior and the observed behavior
Essentially clicking on a legend item disables /enables ALL the traces in the plot instead of the single trace with plotly backend. The behavior is as expected i.e single trace enabled/disabled by clicking on legend entry with Bokeh backend but plotly backend is using the same plotly group for all traces by default hence all traces are enabled/disabled as a group instead of individual traces
documented more  here on this post
https://stackoverflow.com/questions/73494179/is-there-a-way-to-enable-disable-traces-on-an-hvplot-figure-by-clicking-on-legen

I found that changing element.py in plotly  to make legendgroup unique by adding name of trace fixes the issue since plotly click on trace legend to enable disable expects unique legendgroup text for each trace.
C:\Users\user\AppData\Local\Programs\Python\Python310\Lib\site-packages\holoviews\plotting\plotly\element.py  

  ```
def graph_options(self, element, ranges, style, is_geo=False, **kwargs):
        if self.overlay_dims:
            legend = ', '.join([d.pprint_value_string(v) for d, v in
                                self.overlay_dims.items()])
        else:
            legend = element.label
        opts = dict(
            name=legend, **self.trace_kwargs(is_geo=is_geo))
         
        if self.trace_kwargs(is_geo=is_geo).get('type', None) in legend_trace_types:
            opts.update(
                showlegend=self.show_legend, legendgroup=element.group+':'+opts['name']) #  added opts ['name'] to make legend group unique for each trace. This allows enable/disable per trace
```

#### Complete, minimal, self-contained example code that reproduces the issue

```
import pandas as pd
import panel as pn
import hvplot
hvplot.extension('plotly')
#pn.extension(comms="vscode")

#import hvplot.pandas  # noqa
pn.extension(comms='vscode')

from bokeh.sampledata.penguins import data as df
hvexplorer = hvplot.explorer(df)
#clicking on plot legend will disable all traces instead of single trace after following display- BUG
hvexplorer
```
#### Stack traceback and/or browser JavaScript console output

#### Screenshots or screencasts of the bug in action



Discussion:

Resolving patch:
diff --git a/holoviews/plotting/plotly/element.py b/holoviews/plotting/plotly/element.py
--- a/holoviews/plotting/plotly/element.py
+++ b/holoviews/plotting/plotly/element.py
@@ -244,7 +244,7 @@ def graph_options(self, element, ranges, style, is_geo=False, **kwargs):
 
         if self.trace_kwargs(is_geo=is_geo).get('type', None) in legend_trace_types:
             opts.update(
-                showlegend=self.show_legend, legendgroup=element.group)
+                showlegend=self.show_legend, legendgroup=element.group+'_'+legend) # make legendgroup unique for single trace enable/disable
 
         if self._style_key is not None:
             styles = self._apply_transforms(element, ranges, style)


Test patch: