I have a project with a datafile containing images which I would like to peek through using holoviews.Image. When I run the script locally I can interactively see different images within the dataset. The updating function is however called only once when I try running it on renku environment within a jupyterlab notebook.
I tried running
/opt/conda/bin/jupyter labextension install @pyviz/jupyterlab_pyviz ## allows for holoview animations on jupyter notebook on renku environment as I was trying to resolve on my own, but it didn’t help.
Here is a minimal script to reproduce the issue:
import h5py, os, holoviews as hv, requests, pickle, tarfile hv.extension('bokeh') url = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz' r = requests.get(url, allow_redirects=True) fname_z = 'tmp.tar.gz' open(fname_z, 'wb').write(r.content) tar = tarfile.open(fname_z, "r:gz") tar.extractall() tar.close() fname = 'cifar-10-batches-py/data_batch_1' with open(fname, 'rb') as fo: d_data = pickle.load(fo, encoding='bytes') num_images = d_data[b'data'].shape fs = 500 # frame size def select_slice(s): im = d_data[b'data'][s].reshape((3, 32,32)).transpose((1,2,0)) return hv.Image(im).options(cmap='gray', frame_width=fs, frame_height=fs) dmap = hv.DynamicMap(select_slice, kdims=['s']).redim.values(s=range(num_images)) dmap.opts(framewise=True)
Edit: On my project, I am interested in reading a single image from file interactively at a time (to circumvent loading whole dataset into memory). So reading file within
select_slice(s) looks like the following:
with h5py.File(fname, 'r') as fh: im = fh['key_for_images'][s,...]