I work a lot with Geospatial data, and having the ability to quickly show/hide different HoloViews objects (e.g. a satelite tif image and another hv object of e.g. air temperature) would be very useful.
A similiar example is: https://rstudio.github.io/leaflet/showhide.html

Does this functionality already exist? I'm not that familiar with HoloViews internals, but I feel this could work something like:
Many thanks for any help (and many awesome viz libraries!)
Bokeh legends are already clickable to mute/unmute specific traces in some cases, but for that to work in general for map tiles, etc. would currently require creating a corresponding Panel widget that sets the alpha property of each item and selects which map tile provider to use. But it does seem like there could be a custom Bokeh tool that handles this common use case, which would be nice to have...
This would be really awesome to have!
I'm thinking of having a go at this.
I feel this could be implemented as a bokeh tool:
(df.hvplot.points(x="x", y="y") * df.hvplot.line(x="x", y="y")).opts(tools=["layers_control"])
potentially creating a button (e.g. p1, p2 could denote "plot1", "plot2") for each overlay element (I think this is called a glyph is bokeh terminology):

Or as a holoviews option:
(df.hvplot.points(x="x", y="y") * df.hvplot.line(x="x", y="y")).opts(show_layers_control=True)
This could potentially be added to a plot like a legend is (also similar to the image above)
Any help appreciated (mentioning @bryevdv and @philippjfr in case they kindly have any advice), many thanks!
I'm more familiar with Holoview/HoloViz, so thought I try some code:
import pandas as pd
import panel as pn
import param as pm
import hvplot.pandas
df = pd.DataFrame({
"x": [1,2,3],
"y": [1,2,3],
})
show_plot = pn.widgets.Checkbox()
plot = df.hvplot.points(x="x", y="y")
@pn.depends(show_plot.param.value)
def get_plot(value):
return plot.opts(alpha=value)
pn.Column(show_plot, get_plot)
This works, but I think it is generating a new plot (thus may be slow for big or datashaded data). To get around this, following the approach of the NYC taxi demo:
plot = df.hvplot.points(x="x", y="y")
class LayersControl(pm.Parameterized):
# show_plot = pm.Boolean(True) # "couldn't get working"
show_plot = pm.Magnitude(default=1.0)
def viewable(self, **kwargs):
return plot.apply.opts(alpha=self.param.show_plot)
lc = LayersControl()
pn.Column(lc.param, lc.viewable())
Not sure if this is the correct approach, or how it would integrate with the library code.
Most helpful comment
Bokeh legends are already clickable to mute/unmute specific traces in some cases, but for that to work in general for map tiles, etc. would currently require creating a corresponding Panel widget that sets the alpha property of each item and selects which map tile provider to use. But it does seem like there could be a custom Bokeh tool that handles this common use case, which would be nice to have...