Hello,
I have been building a panel application utilizing hvplots and Datashader. I have it working for the most part, but am having poor performance when integrating interactivity.
Observations:
1- I can get great performance when I combine plots in the standard way.
i.e variable.hvplot.quadmesh(…) + variable2.hvplot.quadmesh(…) + etc…
In this case, I get one convenient time slider that controls them all, and it’s really fast for updates.
However, I need more than that, as each plot will have it’s own set of widgets (colorpicker, min/max
limits, others…)
2 - When creating a column for each plot, and combining them into a layout (I am using flexBox), and binding a Player widget , for a bit of extra interactivity, performance crawls to halt on updates.
Below is how I am approaching part 2. If there is anything obvious, or a better approach, it would be much appreciated!
The shape of the data is approximately (315,20,2650), where time is the 315.
This is a stripped down version, with bits missing:
def plotfun(v, clabel,logZ,min,max, cmap):
return v.hvplot.quadmesh(
x="distance", y="altitude",
clim=(min,max),
cmap=cmap,
logz=logZ,
clabel=clabel,
rasterize=True,
xlim=(0, 1.5e+4),
ylim=(0, 2500)
).opts(title=v.attrs["long_name"].replace("_", " "))
player = None
playerText = None
def parseTime(target, event):
target.object = datetime.fromtimestamp(event.new)
for g in groups[2:]:
ds = xr.open_dataset(testFile, group=g, decode_times=False)
plots = pn.FlexBox()
if player is None:
player = pn.widgets.DiscretePlayer(name='time', options=ds.start_time.values.tolist(),value=ds.start_time.values[0])
playerText = pn.widgets.StaticText(name='Time')
playerText.link(player,callbacks={'value':parseTime})
#Plot each variable
for key in ds.variables.keys():
v = ds[key]
col = pn.Column()
#but only those we care about
if v.name in fields:
vi = v.interactive().sel(start_time=player)
col.append(pn.bind(plotfun, vi,"test",False, 0,0.6, 'turbo'))
plots.append(col)
#Add Player after generating all plots
if player is not None:
playerGroup = pn.Column(player, playerText, margin=(0,0,0,75))
plots = pn.Column(playerGroup, plots)
tabs.append((g, plots))
template.main.append(tabs)
template.servable()