Automatically updating bokeh plot

Hi,

I have a data folder which is fed with new data every 30 minutes which is then read into a panda dataframe and plotted as 4 subplotted time series. I am struggling to get these to update when new data comes in and then ultimately be on a password protected web page which continues to update and is interactive.

Any help would be so so appreciated. I am currently just going round in circles…

Here is my plotting code:

import time

import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

from bokeh.io import show, output_notebook, push_notebook, gridplot

from bokeh.plotting import figure, show, output_file

from bokeh.models import HoverTool, Span

from bokeh.charts import TimeSeries

import datetime

output_notebook()

Rubble Buoy

rubble = pd.read_csv(‘X:/rubble_buoy.dat’, usecols=[‘TIMESTAMP’, ‘TSS_shallow_corr_Med’, ‘TSS_deep_corr_Med’,], skiprows=[2,3], na_values=[’-’], index_col=0, parse_dates=True, header=1)

Inshore Buoy

inshore = pd.read_csv(‘X:/inshore_buoy.dat’, usecols=[‘TIMESTAMP’, ‘TSS_shallow_corr_Med’, ‘TSS_deep_corr_Med’,], skiprows=[2,3], na_values=[’-’], index_col=0, parse_dates=True, header=1)

rubble.columns = ['1m ', ‘3m’]

inshore.columns = [‘1m’, ‘2m’]

TOOLS=“hover,crosshair,pan,wheel_zoom,box_zoom,reset,tap,save,box_select,poly_select,lasso_select”

create a new plot

rubble_day = TimeSeries(rubble[-1440:], ylabel=‘mg/l’, xlabel=‘TIME’, width=750, height=500, title=‘Rubble Buoy Last Download %s’ % str(rubble.index[-1]), legend=True, tools=TOOLS)

rubble_day.y_range.start = 0

rubble_day.y_range.end = 80

hline = Span(location=20, dimension=‘width’, line_color=‘red’, line_width=3)

create another one

inshore_day = TimeSeries(inshore[-1440:], ylabel=‘mg/l’, xlabel=‘TIME’, width=750, height=500, title=‘Inshore Buoy Last Download %s’ % str(inshore.index[-1]), legend=True, tools=TOOLS)

inshore_day.y_range.start = 0

inshore_day.y_range.end = 80

rubble_day.renderers.extend([hline])

inshore_day.renderers.extend([hline])

create and another

rubble_hour = TimeSeries(rubble[-60:], ylabel=‘mg/l’, xlabel=‘TIME’, width=500, height=500, title=‘Rubble Buoy’, legend=True, tools=TOOLS)

rubble_hour.y_range.start = 0

rubble_hour.y_range.end = 20

create and another

inshore_hour = TimeSeries(inshore[-60:], ylabel=‘mg/l’, xlabel=‘TIME’, width=500, height=500, title=‘Inshore Buoy’, legend=True, tools=TOOLS)

inshore_hour.y_range.start = 0

inshore_hour.y_range.end = 20

put all the plots in a grid layout

p = gridplot([[rubble_day, rubble_hour], [inshore_day, inshore_hour]])

show the results

#output_file(“layout.html”, title=‘Turbidity Data’)

target = show(p, notebook_handle=True)

update data

rubble = pd.read_csv(‘X:rubble_buoy.dat’, usecols=[‘TIMESTAMP’, ‘TSS_shallow_corr_Med’, ‘TSS_deep_corr_Med’,], skiprows=[2,3], na_values=[’-’], index_col=0, parse_dates=True, header=1)

inshore = pd.read_csv(‘X:inshore_buoy.dat’, usecols=[‘TIMESTAMP’, ‘TSS_shallow_corr_Med’, ‘TSS_deep_corr_Med’,], skiprows=[2,3], na_values=[’-’], index_col=0, parse_dates=True, header=1)

push_notebook(handle=target)

If you are in the notebook, your only option currently is to use push_notebook. and Jupyter interactors. There are examples here:

  https://github.com/bokeh/bokeh/tree/master/examples/howto/notebook_comms

Please note that if you are trying to update data for existing plots in place, you'll have better success and and easier time using bokeh.plotting instead of bokeh.charts. There are lots of examples in the docs and on GitHub of updating data for these kinds of plots.

If you are not actually planning to stay in the notebook, then you want look at a bokeh server application. Again there are lots of examples in the docs and on GitHub, and the same advice about bokeh.plotting applies.

Thanks,

Bryan

···

On Oct 21, 2016, at 5:16 AM, [email protected] wrote:

Hi,

I have a data folder which is fed with new data every 30 minutes which is then read into a panda dataframe and plotted as 4 subplotted time series. I am struggling to get these to update when new data comes in and then ultimately be on a password protected web page which continues to update and is interactive.

Any help would be so so appreciated. I am currently just going round in circles....

Here is my plotting code:

import time
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from bokeh.io import show, output_notebook, push_notebook, gridplot
from bokeh.plotting import figure, show, output_file
from bokeh.models import HoverTool, Span
from bokeh.charts import TimeSeries
import datetime

output_notebook()

# Rubble Buoy
rubble = pd.read_csv('X:/rubble_buoy.dat', usecols=['TIMESTAMP', 'TSS_shallow_corr_Med', 'TSS_deep_corr_Med',], skiprows=[2,3], na_values=['-'], index_col=0, parse_dates=True, header=1)
# Inshore Buoy
inshore = pd.read_csv('X:/inshore_buoy.dat', usecols=['TIMESTAMP', 'TSS_shallow_corr_Med', 'TSS_deep_corr_Med',], skiprows=[2,3], na_values=['-'], index_col=0, parse_dates=True, header=1)

rubble.columns = ['1m ', '3m']
inshore.columns = ['1m', '2m']

TOOLS="hover,crosshair,pan,wheel_zoom,box_zoom,reset,tap,save,box_select,poly_select,lasso_select"

# create a new plot
rubble_day = TimeSeries(rubble[-1440:], ylabel='mg/l', xlabel='TIME', width=750, height=500, title='Rubble Buoy Last Download %s' % str(rubble.index[-1]), legend=True, tools=TOOLS)
rubble_day.y_range.start = 0
rubble_day.y_range.end = 80
hline = Span(location=20, dimension='width', line_color='red', line_width=3)

# create another one
inshore_day = TimeSeries(inshore[-1440:], ylabel='mg/l', xlabel='TIME', width=750, height=500, title='Inshore Buoy Last Download %s' % str(inshore.index[-1]), legend=True, tools=TOOLS)
inshore_day.y_range.start = 0
inshore_day.y_range.end = 80

rubble_day.renderers.extend([hline])
inshore_day.renderers.extend([hline])

# create and another
rubble_hour = TimeSeries(rubble[-60:], ylabel='mg/l', xlabel='TIME', width=500, height=500, title='Rubble Buoy', legend=True, tools=TOOLS)
rubble_hour.y_range.start = 0
rubble_hour.y_range.end = 20

# create and another
inshore_hour = TimeSeries(inshore[-60:], ylabel='mg/l', xlabel='TIME', width=500, height=500, title='Inshore Buoy', legend=True, tools=TOOLS)
inshore_hour.y_range.start = 0
inshore_hour.y_range.end = 20

# put all the plots in a grid layout
p = gridplot([[rubble_day, rubble_hour], [inshore_day, inshore_hour]])

# show the results
#output_file("layout.html", title='Turbidity Data')
target = show(p, notebook_handle=True)

# update data
rubble = pd.read_csv('X:rubble_buoy.dat', usecols=['TIMESTAMP', 'TSS_shallow_corr_Med', 'TSS_deep_corr_Med',], skiprows=[2,3], na_values=['-'], index_col=0, parse_dates=True, header=1)
inshore = pd.read_csv('X:inshore_buoy.dat', usecols=['TIMESTAMP', 'TSS_shallow_corr_Med', 'TSS_deep_corr_Med',], skiprows=[2,3], na_values=['-'], index_col=0, parse_dates=True, header=1)
push_notebook(handle=target)

--
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/95ee03fc-6df4-4ba6-b746-0538616757b3%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.