Trouble with Simple Bokeh Server Test Program

Hi,

I am just starting to mess around with Bokeh, and I’m having a little trouble with getting a simple program to work. I just want the program to dynamically update a simple line plot within a browser. The code is below:

#!/usr/bin/python

import numpy as np

from bokeh.client import push_session

from bokeh.plotting import figure, curdoc

COLOR = “orange”

NUM_CALLBACKS = 500

PLOT_WIDTH = NUM_CALLBACKS

PLOT_HEIGHT = 10

MAX_TIME = 5000

CUR_TIME = 0

CUR_ACCEL = 1

FIGURE = figure(x_range=(0, PLOT_WIDTH), y_range=(0, PLOT_HEIGHT))

FIGURE.border_fill_color = ‘white’

FIGURE.background_fill_color = ‘white’

LINE = FIGURE.line(x = , y = , color = COLOR)

session = push_session(curdoc())

def callback():

‘’’

‘’’

global CUR_TIME

global CUR_ACCEL

CUR_TIME += 1

CUR_ACCEL *= 1.01

LINE.data_source.data[‘x’].append(CUR_TIME)

LINE.data_source.data[‘y’].append(CUR_ACCEL)

print(str((CUR_TIME, CUR_ACCEL)))

curdoc().add_periodic_callback(callback, 100)

I am invoking this program with ‘$bokeh serve test.py --show’, and when I run it, I get the following error message:

“IOError: Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)”

I would really appreciate any help I can get with this.

I want to be able to greatly generalize the functionality within this simple program an application I’m building for my school’s FSAE team. I’m working on an application for our pit crew that will monitor the health of our vehicle (by displaying dynamically updating metrics and plots from data sent to the pit station with an Xbee radio). Ideally, I’d like to have a dashboard of 6-7 plots that are being updated with callback functions as data is received from the vehicle. So, if anyone has any experience with integrating Bokeh API’s with the Python Xbee Library for a similar application and can point me in a direction of some good examples, that would also be a great help.

-Ricky

Hi,

The call to

  session = push_session(curdoc())

is only needed for when you want to connect to a server from a completely different python process (say, in an Jupyter notebook), bot when youare running an application in side the server directly. If you are interested in details, 'bokeh serve test.py' installs an app at an app path of /test, but 'push_session' without any arguments tries to connect to a session at '/' which gives you the error. Remove that line and your app should run. That said, we "make things work" when users user other non-server functions like 'output_server' (by monkey patching them), and we should probably do that for 'push_session' too.

Please note, it is much better to update a data source's data dictionary "in one go", i.e.

  LINE.data_source.data = < new dict >

or possibly

  LINE.data_source.update(x=..., y=...)

than it is to update the x column and y columns separately as you are doing. That generates two messages from the server to the browser which is both inefficient, but more importantly, typically looks wrong (or at least bad) for the brief instant when x has already updated, but y has not.

Bryan

···

On Jan 26, 2016, at 2:49 AM, Ricky Galliani <[email protected]> wrote:

Hi,

I am just starting to mess around with Bokeh, and I'm having a little trouble with getting a simple program to work. I just want the program to dynamically update a simple line plot within a browser. The code is below:

#!/usr/bin/python

import numpy as np

from bokeh.client import push_session
from bokeh.plotting import figure, curdoc

COLOR = "orange"

NUM_CALLBACKS = 500

PLOT_WIDTH = NUM_CALLBACKS
PLOT_HEIGHT = 10

MAX_TIME = 5000
CUR_TIME = 0
CUR_ACCEL = 1

FIGURE = figure(x_range=(0, PLOT_WIDTH), y_range=(0, PLOT_HEIGHT))
FIGURE.border_fill_color = 'white'
FIGURE.background_fill_color = 'white'

LINE = FIGURE.line(x = , y = , color = COLOR)

session = push_session(curdoc())

def callback():
    '''
    '''
    global CUR_TIME
    global CUR_ACCEL
    CUR_TIME += 1
    CUR_ACCEL *= 1.01
    LINE.data_source.data['x'].append(CUR_TIME)
    LINE.data_source.data['y'].append(CUR_ACCEL)
    print(str((CUR_TIME, CUR_ACCEL)))

curdoc().add_periodic_callback(callback, 100)

I am invoking this program with '$bokeh serve test.py --show', and when I run it, I get the following error message:

"IOError: Cannot push session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)"

I would really appreciate any help I can get with this.

I want to be able to greatly generalize the functionality within this simple program an application I'm building for my school's FSAE team. I'm working on an application for our pit crew that will monitor the health of our vehicle (by displaying dynamically updating metrics and plots from data sent to the pit station with an Xbee radio). Ideally, I'd like to have a dashboard of 6-7 plots that are being updated with callback functions as data is received from the vehicle. So, if anyone has any experience with integrating Bokeh API's with the Python Xbee Library for a similar application and can point me in a direction of some good examples, that would also be a great help.

-Ricky

--
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/94492275-124f-4e73-86a8-6e524471edfb%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks, Bryan. That was helpful.

···

On Tuesday, January 26, 2016 at 12:49:26 AM UTC-8, Ricky Galliani wrote:

Hi,

I am just starting to mess around with Bokeh, and I’m having a little trouble with getting a simple program to work. I just want the program to dynamically update a simple line plot within a browser. The code is below:

#!/usr/bin/python

import numpy as np

from bokeh.client import push_session

from bokeh.plotting import figure, curdoc

COLOR = “orange”

NUM_CALLBACKS = 500

PLOT_WIDTH = NUM_CALLBACKS

PLOT_HEIGHT = 10

MAX_TIME = 5000

CUR_TIME = 0

CUR_ACCEL = 1

FIGURE = figure(x_range=(0, PLOT_WIDTH), y_range=(0, PLOT_HEIGHT))

FIGURE.border_fill_color = ‘white’

FIGURE.background_fill_color = ‘white’

LINE = FIGURE.line(x = , y = , color = COLOR)

session = push_session(curdoc())

def callback():

‘’’

‘’’

global CUR_TIME

global CUR_ACCEL

CUR_TIME += 1

CUR_ACCEL *= 1.01

LINE.data_source.data[‘x’].append(CUR_TIME)

LINE.data_source.data[‘y’].append(CUR_ACCEL)

print(str((CUR_TIME, CUR_ACCEL)))

curdoc().add_periodic_callback(callback, 100)

I am invoking this program with ‘$bokeh serve test.py --show’, and when I run it, I get the following error message:

“IOError: Cannot push session document because we failed to connect to the server (to start the server, try the ‘bokeh serve’ command)”

I would really appreciate any help I can get with this.

I want to be able to greatly generalize the functionality within this simple program an application I’m building for my school’s FSAE team. I’m working on an application for our pit crew that will monitor the health of our vehicle (by displaying dynamically updating metrics and plots from data sent to the pit station with an Xbee radio). Ideally, I’d like to have a dashboard of 6-7 plots that are being updated with callback functions as data is received from the vehicle. So, if anyone has any experience with integrating Bokeh API’s with the Python Xbee Library for a similar application and can point me in a direction of some good examples, that would also be a great help.

-Ricky