0

When running the animated code found in (examples/plotting/server/animated.py), I get the error:

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

I have read that removing session = push_session(curdoc()) will resolve the issue as users hosting from localhosts do not need that line, however it is not clear what to replace it with?

Code below:

from numpy import pi, cos, sin, linspace, roll

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

M = 5
N = M*10 + 1
r_base = 8
theta = linspace(0, 2*pi, N)
r_x = linspace(0, 6*pi, N-1)
rmin = r_base - cos(r_x) - 1
rmax = r_base + sin(r_x) + 1

colors = ["FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8", "#253494", "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"] * M

p = figure(x_range=(-11, 11), y_range=(-11, 11))
r = p.annular_wedge(0, 0, rmin, rmax, theta[:-1], theta[1:],
                fill_color=colors, line_color="white")

session = push_session(curdoc())

ds = r.data_source

def update():
    rmin = roll(ds.data["inner_radius"], 1)
    rmax = roll(ds.data["outer_radius"], -1)
    ds.data.update(inner_radius=rmin, outer_radius=rmax)

curdoc().add_periodic_callback(update, 30)

session.show(p) 

session.loop_until_closed() 

1 Answer 1

1

It works for me when I start a Bokeh server in the directory with the Python file with

bokeh serve

and then open a new terminal and execute the Python file with

python animated.py
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I did not know you had to open up a new terminal, silly me. Thank you very much Julian!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.