Interactive array calculations with .interactive(), .bind() and xarray

Hi all,

I’m trying to apply .interactive() and hvplot.bind() to an xarray, basically just multiplying the array with a pn.widgets.IntSlider-controlled multiplier and having the resulting Dataset visualised as an image each time the widget is changed.

I don’t think I get the syntax right though, since the hover-over values and legend do not change when I change the slider.

Running this in a ipynb in VSCode v1.68.0

hvPlot 0.8.0
panel 0.13.1

import rioxarray
import hvplot.xarray
import panel as pn

array = rioxarray.open_rasterio(r'....tif') # GeoTIFF

multiplier = pn.widgets.IntSlider(start=0, end=10, step=1, value=5, name='Multiplier')

def func(array, multiplier): # Can the bound function have more than one argument?

    output_array = array * multiplier
    output_ds = output_array.to_dataset(dim=None, name='name')
    return output_ds

xri = hvplot.bind(func, array, multiplier).interactive()

# For some reason, I have to use the below syntax here to get the graph to display
# using xri.hvplot(groupby='band', ...' directly here does not diplay anything

interactive = (
    xri.hvplot(groupby='band', frame_width=600, data_aspect=1)


The array’s repr below:

Any advice on what I’m not getting? Thanks a mil!

Without data, it is hard to know what the problem is.

Have you tested it in jupyter lab/notebook and see if it works there? If it does, try setting pn.config.comms = 'vscode' at the top of the script.

Ah excellent - should have thought of just running it in jupyter-lab instead.

Cannot get it to work in VSCode with the additional line at the top, and after conda install -c bokeh jupyter_bokeh.

ModuleNotFoundError: No module named 'jupyter_bokeh.widgets'

But no worries, I’ll just use jupyter lab from now on.

Thank you!