Hi,
I’m experimenting with manipulating datashader plots in bokeh and would like to do so within server apps. I think this is still bokeh question anyway.
My starting point is to adapt the NYC taxi notebook to minimal code (below). The issue is that the resulting server plot does not resample as I operate the wheel zoom, while it does resample when InteractiveImage is run within the jupyter notebook (and it’s awesome when it does). This makes me think I have not set up the document properly (curdoc) or that I’m not properly using the callback. The object help for datashader.bokeh_ext (Also below) indicates that this is possible (“could be extended to use Bokeh server in that case”) but I can’t tell how.
Any advice?
Apart from InteractiveImage, is there another way to obtain a dynamically updating datashader plot in a boker server app?
Many thanks,
JT
import pandas as pd
from bokeh.plotting import figure, output_notebook, show
import datashader as ds
from datashader import transfer_functions as tf
from datashader.colors import colormap_select, Hot
from bokeh.io import curdoc
from functools import partial
from datashader.bokeh_ext import InteractiveImage
from IPython.core.display import HTML, display
read in the Taxi dataset
df = pd.read_csv(‘data/nyc_taxi.csv’,usecols= \
['pickup_x', 'pickup_y', 'dropoff_x','dropoff_y', 'passenger_count','tpep_pickup_datetime'])
NYC = x_range, y_range = ((-8242000,-8210000), (4965000,4990000))
p = figure(tools=‘pan,wheel_zoom,reset’, plot_width=1000, plot_height=1000,
x_range=x_range, y_range=y_range, outline_line_color=None,
min_border=0, min_border_left=0, min_border_right=0,
min_border_top=0, min_border_bottom=0)
def create_image(x_range, y_range, w=800, h=800):
cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
agg = cvs.points(df, 'dropoff_x', 'dropoff_y', ds.count('passenger_count'))
img = tf.shade(agg, cmap=Hot, how='eq_hist')
return tf.dynspread(img, threshold=0.5, max_px=4)
im = InteractiveImage(p, create_image)
curdoc().add_root(p)
Help on class InteractiveImage in module datashader.bokeh_ext:
class InteractiveImage(builtin.object)
···
Bokeh-based interactive image object that updates on pan/zoom
events.
Given a Bokeh plot and a callback function, calls the function
whenever the pan or zoom changes the plot’s extent, regenerating
the image dynamically. Works in a Jupyter/IPython notebook cell,
using the existing notebook kernel Python process (not a separate
Bokeh server). Does not yet support usage outside the notebook,
but could be extened to use Bokeh server in that case.