hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Limitations of the .interactive API

Open jbednar opened this issue 5 years ago • 3 comments

The new .interactive API is really fun to work with, but I'm bumping up against either its limits or my own imagination. E.g. if I start with this example that works well:

import panel as pn, xarray as xr, holoviews as hv, hvplot.xarray
pn.extension()

ds = xr.tutorial.open_dataset('air_temperature')
image = ds.hvplot('lon', 'lat')
stream = hv.streams.Tap(source=image, x=-88+360, y=40)
timeseries = ds.interactive.sel(lon=stream.param.x, lat=stream.param.y,
                                method="nearest").hvplot('time')

pn.Column(image, timeseries.dmap())

image

That's great, but then I want to put some indication of where I tapped, as a red dot in the first plot and as numeric values in the second plot. I can't quite see how to do it. A start, with nothing actually connected:

import panel as pn, xarray as xr, holoviews as hv, hvplot.xarray
pn.extension()

ds = xr.tutorial.open_dataset('air_temperature')
image = ds.hvplot('lon', 'lat')
stream = hv.streams.Tap(source=image, x=-88+360, y=40)
point = hv.Points([(260,40)]).opts(size=5, color="red")
timeseries = ds.interactive.sel(lon=stream.param.x, lat=stream.param.y,
                                method="nearest").hvplot('time').relabel(f"lon: {stream.x}, lat: {stream.y}")

pn.Column(image*point, timeseries.dmap())

image

I could write a DynamicMap returning a Points object, but that's an entirely new concept, so I'm wondering whether there is some .apply or other more reactive approach that fits better with the rest of the code here, i.e. without an explicit callback.

Also not sure how to specify the title properly in the second plot; stream.param.x won't work, as it just shows the Parameter object itself rather than fetching the current value. Is there a clean way?

It also might be nice to have an automatic way of getting the default title for the second plot, via hvPlot and .interactive somehow connecting up widget values to the title the same way NdOverlays do, but I guess that would be a separate issue.

jbednar avatar Dec 04 '20 22:12 jbednar

Also, will dim() expressions work with .interactive()? If so, they should presumably be in the https://hvplot.holoviz.org/user_guide/Interactive.html docs. If not, can they?

jbednar avatar Dec 10 '20 20:12 jbednar

I really like this example!

The way to customize the plot title is to give to title a bound function. Credits goes to Philipp for that, I remember him showing that at PyData Berlin this year:

import panel as pn, xarray as xr, holoviews as hv, hvplot.xarray
pn.extension()

def title(x, y):
    return f'lon={x:.2f}, lat={y:.2f}'

ds = xr.tutorial.open_dataset('air_temperature')
image = ds.hvplot('lon', 'lat')
stream = hv.streams.Tap(source=image, x=-88+360, y=40)
point = hv.Points([(260,40)]).opts(size=5, color="red")
timeseries = ds.interactive.sel(lon=stream.param.x, lat=stream.param.y,
                                method="nearest").hvplot('time', title=pn.bind(title, stream.param.x, stream.param.y))

pn.Column(image*point, timeseries.dmap())

My limited feedback on this example would be that:

  • as a hvPlot user I'd rather not have to use HoloViews directly , or at least have one place where the streams I can use are documented. I think this is very similar to the documentation of the Panel widgets that a hvPlot user might want to inject in a pipeline. I think we said that hvPlot should document the most common widgets and then link to the Reference Gallery of Panel. There's a Stream section in HoloViews' Reference Gallery but as streams are very useful on their own there's lots of HoloViews code in there which might be confusing to hvPlot users.
  • in this particular example it'd be indeed nice to have a simple way to have a marker to show the last selected location, maybe that should be the default?

@philippjfr do you have ideas on how to improve that?

maximlt avatar Oct 21 '22 04:10 maximlt

I agree with all that feedback. Now I sit back and hope for it all to happen, magically!

jbednar avatar Oct 21 '22 20:10 jbednar