Bokeh Serve Error

I am new to Bokeh, so my question may be trivial to answer. I’m spent some time in the tutorials and documentation, and I can’t find a solution, so here I am. I am using Python 2.7 with Bokeh 0.12.3 in Windows 10. I am trying to update a rather large block of data using figure.image(…), large being in the neighborhood of 15 or so rows by 800000 elements wide. I will need to update this image every 30s or so. I have cluged code together from a few examples that is a first step toward what I need that represents the issue I am having. The code to reproduce the error is shown below. When I run this code with ‘bokeh serve --show [filename.py]’, it opens a tab in Internet Explorer to view the output, but a plot never shows up and I get the following output in the command window:

2016-12-22 15:47:20,269 Starting Bokeh server version 0.12.3
2016-12-22 15:47:20,279 Starting Bokeh server on port 5006 with applications at paths [’/bokeh_stream’]
2016-12-22 15:47:20,282 Starting Bokeh server with process id: 6476
2016-12-22 15:47:21,973 200 GET /bokeh_stream (127.0.0.1) 656.00ms
2016-12-22 15:47:22,278 WebSocket connection opened
2016-12-22 15:47:22,279 ServerConnection created
2016-12-22 15:48:10,992 received invalid integer in pong ‘’
Traceback (most recent call last):
File “C:\Users\codsmit\AppData\Local\Continuum\Anaconda2\envs\xprong_gpu\lib\site-packages\bokeh\server\views\ws.py”, line 167, in on_pong
self.latest_pong = int(codecs.decode(data, ‘utf-8’))
ValueError: invalid literal for int() with base 10: ‘’
2016-12-22 15:49:04,286 received invalid integer in pong ‘’
Traceback (most recent call last):
File “C:\Users\codsmit\AppData\Local\Continuum\Anaconda2\envs\xprong_gpu\lib\site-packages\bokeh\server\views\ws.py”, line 167, in on_pong
self.latest_pong = int(codecs.decode(data, ‘utf-8’))
ValueError: invalid literal for int() with base 10: ‘’

Another ‘ValueError’ shows up periodically in the window. However, if I change the ‘width = 192000’ to ‘width = 192000 / 2’ in the code, the correct plot will show up in the web browser, but I get the following command window output. Note the Bokeh Protocol error:

2016-12-22 15:44:39,890 Starting Bokeh server version 0.12.3
2016-12-22 15:44:39,901 Starting Bokeh server on port 5006 with applications at paths [’/bokeh_stream’]
2016-12-22 15:44:39,904 Starting Bokeh server with process id: 17732
2016-12-22 15:44:41,137 200 GET /bokeh_stream (127.0.0.1) 331.00ms
2016-12-22 15:44:41,456 WebSocket connection opened
2016-12-22 15:44:41,457 ServerConnection created
2016-12-22 15:45:25,017 error handling message Message ‘PATCH-DOC’ (revision 1): KeyError(‘references’,)
2016-12-22 15:45:25,023 Bad header with no msgtype was: {}
2016-12-22 15:45:25,026 Bokeh Server protocol error: No ‘msgtype’ in header, closing connection
2016-12-22 15:45:25,029 Bad header with no msgtype was: {}
2016-12-22 15:45:25,032 Bokeh Server protocol error: No ‘msgtype’ in header, closing connection
2016-12-22 15:45:25,033 Bad header with no msgtype was: {}
2016-12-22 15:45:25,036 Bokeh Server protocol error: No ‘msgtype’ in header, closing connection
2016-12-22 15:45:25,039 WebSocket connection closed: code=None, reason=None

Code to reproduce the error:

from bokeh.layouts import column
from bokeh.plotting import figure, curdoc
import numpy as np

width = 192000
x = np.linspace(0, width, width4)
h = 4
y = np.linspace(0, h, h
4)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx)*np.cos(yy)

create a plot and style its properties

p = figure(x_range=(0, width), y_range=(0, h), toolbar_location=None)
p.border_fill_color = ‘black’
p.background_fill_color = ‘black’
p.outline_line_color = None
p.grid.grid_line_color = None
r = p.image(image=, x=0, y=0, dw=width, dh=h, palette=“RdYlGn11”)
ds = r.data_source

def callback():
new_data = dict()
new_data[‘image’] = [d]
ds.data = new_data

curdoc().add_next_tick_callback(callback)
curdoc().add_root(column(p))

Are there any ideas out there for why increasing the width of the data will crash the Bokeh server? This isn’t the data I need to show, but it is sized to represent the size of output I will need.

Thanks in advance,

Cody

Hi, a few general comments:

There is an open PR (https://github.com/bokeh/bokeh/pull/5544\) to add a binary encoding option for arrays, which in particular will help with image performance in Bokeh.

However, even with that said, it's almost certainly the case that you are never going to want to sent 15x800k data points directly to the browser. You're looking at transferring 10s or 100s of MB of data to a web page, maybe 0.2 percent of which could actually be viewed at one instant given typical screen resolutions.

So what are some different possibilities. If these are just static images, even if there are alot of them, maybe Bokeh is just not the right tool. Bokeh is designed for highly interactive apps, and that implies certain trade-offs. If you can just render them all up front with some other tool, maybe that's the best option.

If you want interactivity over this data, or if the data is updating, etc., then Bokeh might be *part* of a solution. If you want to be able to pan, zoom, etc on this large image, then the right option might be Bokeh+Datashader. The Datashader is specifically built to help with visualizing larger data sets, including perceptually efficacious downsampling to sizes that are comparable to screen resolution (i.e. are reasonable for Bokeh to handle). It integrates very will with Bokeh. You can find the Datashader project on GitHub:

  GitHub - holoviz/datashader: Quickly and accurately render even the largest data.

Alternatively, you can implement some downsampling algorithm or technique yourself, in your bokeh server app. But the bottom line is that sending 12 million points into the browser is not going to work well.

Thanks,

Bryan

···

On Dec 22, 2016, at 4:56 PM, [email protected] wrote:

I am new to Bokeh, so my question may be trivial to answer. I'm spent some time in the tutorials and documentation, and I can't find a solution, so here I am. I am using Python 2.7 with Bokeh 0.12.3 in Windows 10. I am trying to update a rather large block of data using figure.image(...), large being in the neighborhood of 15 or so rows by 800000 elements wide. I will need to update this image every 30s or so. I have cluged code together from a few examples that is a first step toward what I need that represents the issue I am having. The code to reproduce the error is shown below. When I run this code with 'bokeh serve --show [filename.py]', it opens a tab in Internet Explorer to view the output, but a plot never shows up and I get the following output in the command window:

2016-12-22 15:47:20,269 Starting Bokeh server version 0.12.3
2016-12-22 15:47:20,279 Starting Bokeh server on port 5006 with applications at paths ['/bokeh_stream']
2016-12-22 15:47:20,282 Starting Bokeh server with process id: 6476
2016-12-22 15:47:21,973 200 GET /bokeh_stream (127.0.0.1) 656.00ms
2016-12-22 15:47:22,278 WebSocket connection opened
2016-12-22 15:47:22,279 ServerConnection created
2016-12-22 15:48:10,992 received invalid integer in pong ''
Traceback (most recent call last):
  File "C:\Users\codsmit\AppData\Local\Continuum\Anaconda2\envs\xprong_gpu\lib\site-packages\bokeh\server\views\ws.py", line 167, in on_pong
    self.latest_pong = int(codecs.decode(data, 'utf-8'))
ValueError: invalid literal for int() with base 10: ''
2016-12-22 15:49:04,286 received invalid integer in pong ''
Traceback (most recent call last):
  File "C:\Users\codsmit\AppData\Local\Continuum\Anaconda2\envs\xprong_gpu\lib\site-packages\bokeh\server\views\ws.py", line 167, in on_pong
    self.latest_pong = int(codecs.decode(data, 'utf-8'))
ValueError: invalid literal for int() with base 10: ''

Another 'ValueError' shows up periodically in the window. However, if I change the 'width = 192000' to 'width = 192000 / 2' in the code, the correct plot will show up in the web browser, but I get the following command window output. Note the Bokeh Protocol error:

2016-12-22 15:44:39,890 Starting Bokeh server version 0.12.3
2016-12-22 15:44:39,901 Starting Bokeh server on port 5006 with applications at paths ['/bokeh_stream']
2016-12-22 15:44:39,904 Starting Bokeh server with process id: 17732
2016-12-22 15:44:41,137 200 GET /bokeh_stream (127.0.0.1) 331.00ms
2016-12-22 15:44:41,456 WebSocket connection opened
2016-12-22 15:44:41,457 ServerConnection created
2016-12-22 15:45:25,017 error handling message Message 'PATCH-DOC' (revision 1): KeyError('references',)
2016-12-22 15:45:25,023 Bad header with no msgtype was: {}
2016-12-22 15:45:25,026 Bokeh Server protocol error: No 'msgtype' in header, closing connection
2016-12-22 15:45:25,029 Bad header with no msgtype was: {}
2016-12-22 15:45:25,032 Bokeh Server protocol error: No 'msgtype' in header, closing connection
2016-12-22 15:45:25,033 Bad header with no msgtype was: {}
2016-12-22 15:45:25,036 Bokeh Server protocol error: No 'msgtype' in header, closing connection
2016-12-22 15:45:25,039 WebSocket connection closed: code=None, reason=None

Code to reproduce the error:

from bokeh.layouts import column
from bokeh.plotting import figure, curdoc
import numpy as np

width = 192000
x = np.linspace(0, width, width*4)
h = 4
y = np.linspace(0, h, h*4)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx)*np.cos(yy)

# create a plot and style its properties
p = figure(x_range=(0, width), y_range=(0, h), toolbar_location=None)
p.border_fill_color = 'black'
p.background_fill_color = 'black'
p.outline_line_color = None
p.grid.grid_line_color = None
r = p.image(image=, x=0, y=0, dw=width, dh=h, palette="RdYlGn11")
ds = r.data_source

def callback():
    new_data = dict()
    new_data['image'] = [d]
    ds.data = new_data

curdoc().add_next_tick_callback(callback)
curdoc().add_root(column(p))

Are there any ideas out there for why increasing the width of the data will crash the Bokeh server? This isn't the data I need to show, but it is sized to represent the size of output I will need.

Thanks in advance,

Cody

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/dcfe4fe7-8594-40af-bacd-0c1fefe70440%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.