0

I am trying to follow this example notebook, specifically the plotting section where it plots the x,y grid and loops/scrolls through the time dimension.

ds.air.interactive.sel(time=pnw.DiscreteSlider).plot()

I'm running into two issues. The first is, I'd like to run this code in the Spyder IDE, which does not support the inline widgets. Based on a few other questions I've found here, the solution seems to be to have the interactive widget render in a browser window. I've looked around a few spots, like this question, but I can't seem to find anything that works with the hvplot.xarray.XArrayInteractive objects that are created here. So my first question is how to get these to render in a browser window.

My second question is how to save these loops as an html file that can be opened later. I've tried using the tutorial here, but when I try to save it, I get the following error.

ValueError: HoloViews pane does not support objects of type 'XArrayInteractive'.

It seems like in both cases, using this "XArrayInteractive" type might be causing the issue. I am not locked into using this method, if there is another way to make the loops I want, I am open to that.

Thanks

hm8
  • 1,381
  • 3
  • 21
  • 41

1 Answers1

0

I figured out how to get this to work in Spyder. Here is a full code example from https://hvplot.holoviz.org/ showing the additional lines of code to get it to work in Spyder:

import hvplot.xarray
import panel as pn
import xarray as xr
hv.extension('bokeh')
da = xr.tutorial.open_dataset('air_temperature').air
w_quantile = pn.widgets.FloatSlider(name='quantile', start=0, end=1)
w_time = pn.widgets.IntSlider(name='time', start=0, end=10)

app = da.interactive(loc='left') \
.isel(time=w_time) \
.quantile(q=w_quantile, dim='lon') \
.hvplot(ylabel='Air Temperature [K]', width=500)

app.layout().show(threaded=True) # displays the interactive dashboard
app.layout().save("dashboard.html", embed=True) # saves the html file

The last two lines are the secret. The interactive command returns an hvplot.xarray.XArrayInteractive object Which does not work with the methods described in the first link you referenced. The app.layout() command returns a panel object; which you can use to plot in Spyder. There is more information in the last link about this.

Marcus
  • 1