Refresh choropleth map without server interaction


I’ve been watching for a few times Sara Bird’s talk on choropleth maps with bokeh here

and thanks to that video I got a basic map working with polygons (coming from a GeoJSON projected to Web Mercator EPSG:3857),

filled with colors depending on values from a pandas dataframe, using STAMEN_TERRAIN as tiles provider.

I was wondering how could this choropleth map be refreshed with filters coming from a selector without a server interaction?

I know in Sarah’s video it is mentioned something about “actions”, and I digged a bit in the source code checking things regarding CustomJS,

but I am not sure how to procede.

It looks I should somehow inject some custom javascript into the python API, but I struggle

to find hooks in the examples and I am not really sure where should I look in the docs.

Ideally I would like to apply that filter from a selector to a pandas dataframe like a “groupby” where the

filtered records have all the same structure so then the choropleth map finds the fields where expected.

The selector is a year quarter e.g. for today July 2017 is “2017-Q2” as a value for the cell in the rows to filter.

I am working with jupyter notebooks at the moment, but I would like to run a python script

to generate static HTML files once this filtering thing works without the need of a backend.

This is an extract of the code:

source_data = ColumnDataSource(data=merged_df)

fig.patches(‘xs’, ‘ys’, source=source_data,

fill_color={‘field’: ‘median’, ‘transform’: color_mapper},

fill_alpha=0.5, line_color=“black”, line_width=0.5)

This is the head of the dataframe:


2017-Q2,MY_POLYGON_NAME_VALUE,108.0,531.67,80000.0,2266.992315,1527.27,(the longitude coords),(the latitude coords)

Thank you