Cannot display DynamicMap inside a JupyterLab notebook
See original GitHub issueHello,
I can’t seem to figure out how to run the Game of Life example inside a notebook in JupyterLab 0.32.1
with holoviews 1.10.4
, bokeh 0.12.15
.
The JupyterLab is running on localhost:8888
.
First cell
import numpy as np
import holoviews as hv
from holoviews.streams import Tap, Counter
from scipy.signal import convolve2d
renderer = hv.renderer('bokeh')
diehard = [[0, 0, 0, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 1, 1]]
boat = [[1, 1, 0],
[1, 0, 1],
[0, 1, 0]]
r_pentomino = [[0, 1, 1],
[1, 1, 0],
[0, 1, 0]]
beacon = [[0, 0, 1, 1],
[0, 0, 1, 1],
[1, 1, 0, 0],
[1, 1, 0, 0]]
acorn = [[0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0],
[1, 1, 0, 0, 1, 1, 1]]
spaceship = [[0, 0, 1, 1, 0],
[1, 1, 0, 1, 1],
[1, 1, 1, 1, 0],
[0, 1, 1, 0, 0]]
block_switch_engine = [[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 1, 1],
[0, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 0, 0]]
glider = [[1, 0, 0], [0, 1, 1], [1, 1, 0]]
unbounded = [[1, 1, 1, 0, 1],
[1, 0, 0, 0, 0],
[0, 0, 0, 1, 1],
[0, 1, 1, 0, 1],
[1, 0, 1, 0, 1]]
shapes = {'Glider': glider, 'Block Switch Engine': block_switch_engine,
'Spaceship': spaceship, 'Acorn': acorn, 'Beacon': beacon,
'Diehard': diehard, 'Unbounded': unbounded}
def step(X):
nbrs_count = convolve2d(X, np.ones((3, 3)), mode='same', boundary='wrap') - X
return (nbrs_count == 3) | (X & (nbrs_count == 2))
def update(pattern, counter, x, y):
if counter:
img.data = step(img.data)
if x and y:
pattern = np.array(shapes[pattern])
r, c = pattern.shape
y, x = img.sheet2matrixidx(x,y)
img.data[y:y+r,x:x+c] = pattern[::-1]
return hv.Image(img)
title = 'Game of Life - Tap to place pattern, Doubletap to clear'
opts = {
'style': {'cmap': 'gray', 'toolbar': False, },
'plot' : {'height': 400, 'width': 800, 'title_format': '{label}',
'xaxis': None, 'yaxis': None}
}
img = hv.Image(np.zeros((100, 200), dtype=np.uint8))
counter, tap = Counter(transient=True), Tap(transient=True)
pattern_dim = hv.Dimension('Pattern', values=sorted(shapes.keys()))
dmap = hv.DynamicMap(update, kdims=[pattern_dim], streams=[counter, tap])
# doc = renderer.server_doc(dmap.redim.range(z=(0, 1)).opts(**opts))
# doc.title = 'Game of Life'
app = renderer.app(dmap.redim.range(z=(0, 1)).opts(**opts), show=True, websocket_origin='localhost:8888')
gives:
INFO:bokeh.server.server:Starting Bokeh server version 0.12.15 (running on Tornado 5.0.2)
Second cell:
dmap.periodic(0.05)
gives no output – it keeps running and upon interruption, it is clear that it can’t connect:
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-8f5136ab6c88> in <module>()
----> 1 dmap.periodic(0.05)
.../python3.6/site-packages/holoviews/core/spaces.py in __call__(self, period, count, param_fn, timeout, block)
692 instance = self._periodic_util(period, count, inner,
693 timeout=timeout, block=block)
--> 694 instance.start()
695 self.instance= instance
696
.../python3.6/site-packages/holoviews/core/util.py in start(self)
174 super(periodic,self).start()
175 else:
--> 176 self.run()
177
178 def stop(self):
.../python3.6/site-packages/holoviews/core/util.py in run(self)
190 while not self.completed:
191 if self.block:
--> 192 time.sleep(self.period)
193 else:
194 self._completed.wait(self.period)
KeyboardInterrupt:
Any help would be greatly appreciated 😃
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Dynamicmap (and holomap) responsiveness when running ...
Dynamic(). It shows but doesn't respond when called directly within the vscode notebook, still really unresponsive when served as a panel. The ...
Read more >HoloViews DynamicMap with stream only passes display ...
I'm struggling with that code inside a stream function is only once passed on to IPython. In other words, display() calls from DynamicMap...
Read more >Ipyleaflet map object doesn't display in Jupyter Notebook but it ...
It just doesn't get rendered. Any hints? After a while, this message appears : "A Jupyter widget could not be displayed because the...
Read more >DynamicMap — HoloViews v1.15.3
Download this notebook from GitHub (right-click to download). ... and for the user-guide describing DynamicMap in more detail, see the Live Data user...
Read more >Display Troubleshooting — Altair 4.2.0 documentation
Altair has a number of moving parts: it creates data structures in Python, ... If you are working in a notebook environment, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To be able to display it in a notebook you need to make sure to load the extension first with:
After that the changes you made to display as an app inside the notebook seem to work for me.
It’s not detectable unfortunately, doing it without loading the extension is perfectly valid since it just serves the app on a different port, which you could access in a new browser window.