Bokeh interactive live streaming plots

Hi all,

I am relatively new to bokeh and want to start using it for my day to day data analysis as well as live monitoring at work. Basically what I am aiming for is a streaming line plot which has the added functionality of checkboxs to toggle on and off certain lines on my plot. Ive basically been combining the example as well as the random_walk.ipynb example. I’ve pasted what I have at the moment below. Im basically stuck at the point trying to get the checkboxs to toggle the lines on and off but Im not sure how this should be done. I would prefer to have this run through an ipython notebook if possible.

thanks for your help!


import time

import random

import numpy as np

import datetime

from bokeh.plotting import cursession, figure, show, output_server

from bokeh.models import GlyphRenderer, HoverTool, BoxSelectTool

from bokeh.models.widgets import Toggle

from import output_file, push, hplot,HBox

from bokeh.models.widgets import CheckboxGroup

from bokeh.models import (DatetimeAxis,

DatetimeTickFormatter, Grid, Legend, Plot, NumeralTickFormatter


class LinePlotStreamer(HBox):

def init(self):

self.checkbox_group = CheckboxGroup(labels=[“line 1”, “line 2”], active=[1])


x = np.array([,])#np.linspace(0,0)

y = np.array([0,0])

z = np.array([0,0])

#TOOLS = [BoxSelectTool(), HoverTool()]

toolset = “crosshair,pan,reset,resize,save,wheel_zoom”

self.p = figure(title=“Simple streaming example”, width=600,height=500,

tools=toolset, x_axis_type = “datetime”)

self.p.line(x,y, color="#2222aa", line_width=2, legend=‘line 1’)

self.p.line(x,z, color="#FB9A99", line_width=2, legend=‘line 2’)

xformatter = DatetimeTickFormatter(formats=dict(hours=["%H"],minutes=["%M"],seconds=["%S"]))

xaxis = DatetimeAxis(formatter=xformatter)

p.add_layout(xaxis, ‘below’)

self.p.yaxis[0].formatter = NumeralTickFormatter(format="$0.00")



self.ds ={“type”: GlyphRenderer})[0].data_source

self.ds2 ={“type”: GlyphRenderer})[1].data_source

def setup_events(self):


def checkbox_handler(self,active):

print(“toggle switched”)


def update_data(self,hide=False):

oldx =[“x”]

oldy =[“y”]

oldz =[“y”]

rand = random.random()

rand2 = random.random()

newy = np.hstack([oldy, [rand]])

newz = np.hstack([oldz, [0.5]])

newx = np.hstack([oldx,])

plot_data_x =

plot_data_y =

plot_data_z =

for p in

if p ==0:

plot_data_x = newx

plot_data_y = newy

if p ==1:

plot_data_x = newx

plot_data_z = newz[“x”] = plot_data_x[“y”] = plot_data_y[“x”] = plot_data_x[“y”] = plot_data_z




plot = LinePlotStreamer()

counter =0

while True:

counter += 1