Errors when nesting Overlays and DynamicMaps
See original GitHub issueThe stacktraces below were from master (as of last night), but I first ran into all these problems on the latest stable.
Following up on some questions I asked on gitter. I start with a analysis function that dynamically generates holoviews objects, possibly Overlays/Layouts, that include large Images and/or Curves. My goal is to regrid all Images (and datashade all Curves). For the following minimal test case, I precompute these holoviews plots and store them in dicts (dat1 and dat2); in my production code, these may be cached in a dict or dynamically generated (so z needs to be a kdim of a DynamicMap, not a HoloMap).
Set up the plots:
import numpy as np
import holoviews as hv
from holoviews.operation.datashader import datashade, regrid
hv.notebook_extension('bokeh')
dat1 = {}
dat2 = {}
for z in range(10):
dat1[z] = hv.Image(np.random.random((1000,1000)), bounds=(0,0,10,10)) * hv.HLine(z)
dat2[z] = hv.Curve((np.random.random(1000) - 0.5).cumsum()) * hv.VLine(z*100)
With no datashader, this works as expected:
def cb(z):
return dat1[z]
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap
It shows a slider for z, and I can easily browse around.
It would be great to be able to write dmap.map(regrid, hv.Image) and have that work. Maybe one day? 😃 I assumed I needed to call .map() before I combine all the z-slices into a DynamicMap, like this:
def cb(z):
return dat1[z].map(regrid, hv.Image)
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap
This fails. Stacktrace: https://gist.github.com/shenker/16b66fda15093544e9d86d69a60a12af
Heeding the warning message about .collate(), I try:
def cb(z):
return dat1[z].map(regrid, hv.Image).collate()
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap
This also fails, with the same error. With either of these, if instead of displaying dmap, I display, e.g., dmap[4], I get an individual image and the dynamic regridding works just fine (obviously, no scroll bar for z).
I was wondering if this issue was specific to hv.Image, so I also tried the above substituting dat1 with dat2 and regrid with datashade, but this failed in similar ways.
Returning to the original working example without datashader,
def cb(z):
return dat1[z]
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
If I try simply dmap.collate(), I get this stacktrace when I use dat1 (with Images) and this stacktrace when I use dat2 (with Curves).
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)

Top Related StackOverflow Question
If you’re working with a small set of elements and declaring them ahead of time I’d recommend just using a HoloMap btw. Here’s how I’d write your example:
Would it be possible to detect nested DynamicMaps and raise an error with your suggestions above? It sounds like the current behavior is very confusing, i.e. that it gives a blank plot rather than some more direct indication that something that seems reasonable is not supported.