Hi Bokeh Community,

Originally, I’m trying to create a multi-select widget with metrics options to toggle on the hover over on a gmap plot. I was inspired by this:

https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/4zwyPhPlTn4

I follow the examples pretty much function by function with the exception of curdoc as I’m just trying to show a working example and not add to a bokeh server (?) I’m not sure if that has any bearing on this situation. Basically it plots and the values are read in well, but I don’t think the javascript is working beneath it.

Hopefully this loads for you guys, if anything breaks, lmk. Would really appreciate this as I’m doing this for a big graduating project for my masters!

Here’s my code

import pickle

import numpy as np

import pandas as pd

import geopandas as gpd

import bokeh

from bokeh.io import output_notebook, show

from bokeh.plotting import figure

from bokeh.models import ColumnDataSource, HoverTool, LogColorMapper, GMapOptions, GMapPlot, Patches, HoverTool, CustomJS

from bokeh.models.widgets import Slider, Button, CheckboxButtonGroup, CheckboxGroup, TableColumn, Panel, DataTable, DateFormatter, TableColumn, MultiSelect, Select

from bokeh.io import output_file, show, curdoc, save

from bokeh.palettes import YlGn as palette

from bokeh.layouts import Column, widgetbox, Row

from bokeh.plotting import gmap

from shapely.geometry import Polygon, Point

import matplotlib.pyplot as plt

from matplotlib.pyplot import *

from gmplot import gmplot

palette = palette[9]

palette.reverse()

color_mapper = LogColorMapper(palette=palette)

%matplotlib inline

df = pickle.load(open(“pickles/grid_df.pkl”, “rb”))

``

df.drop([“halibut_trawl_sites”, “marinas”, “oil_platforms”, “piers”], axis = 1, inplace = True)

#Convert columns to lists for column data source

xs = [df[“geometry”][i].exterior.xy[0].tolist() for i in range(df.shape[0])]

ys = [df[“geometry”][i].exterior.xy[1].tolist() for i in range(df.shape[0])]

biomass_kg = df.biomass.tolist()

water_depth_m = df.depth.tolist()

sst = df.mean_sst.tolist()

species = [df.critical_species[i][0][1] for i in range(df.shape[0])]

critical_species_distance = [df.critical_species[i][0][2] for i in range(df.shape[0])]

county = [df.county[i][0][1] for i in range(df.shape[0])]

county_distance = [df.county[i][0][2] for i in range(df.shape[0])]

pretected_areas = [df.pretected_areas[i][0][1] for i in range(df.shape[0])]

pretected_areas_distance = [df.pretected_areas[i][0][2] for i in range(df.shape[0])]

estab = [df.nes_estab_pct[i][0][1] for i in range(df.shape[0])]

estab_perc = [df.nes_estab_pct[i][0][2] for i in range(df.shape[0])]

avg_emp = [df.annual_avg_emplvl[i][0][1] for i in range(df.shape[0])]

avg_emp_perc = [df.annual_avg_emplvl[i][0][2] for i in range(df.shape[0])]

qcew = [df.qcew_emp_pct[i][0][1] for i in range(df.shape[0])]

qcew_perc = [df.qcew_emp_pct[i][0][2] for i in range(df.shape[0])]

unemployment = [df.unemployment_rate[i][0][1] for i in range(df.shape[0])]

ndvi = df.ndvi.tolist()

min_light = df.z_min_light.tolist()

mixed_l = df.z_mixedl.tolist()

floor_temp = df.floor_temp.tolist()

viable = df.viable.tolist()

boat_launches = [df.boat_launches[i][0][1] for i in range(df.shape[0])]

boat_launches_distance = [df.boat_launches[i][0][2] for i in range(df.shape[0])]

shoretype = [df.shoretype[i][0][1] for i in range(df.shape[0])]

shoretype_distance = [df.shoretype[i][0][2] for i in range(df.shape[0])]

shoretype2 = [df.shoretype2[i][0][1] for i in range(df.shape[0])]

shoretype2_distance = [df.shoretype2[i][0][2] for i in range(df.shape[0])]

aerial_kelp = [df.aerial_kelp[i][0][2] for i in range(df.shape[0])]

admin_kelp = df.admin_kelp_bed.tolist()

#Gmap plotting - I’m hiding my google api key, but you could easily get one here: https://developers.google.com/maps/documentation/javascript/get-api-key

def create_plot():

```
p = gmap("YOUR_OWN_GOOGLE_API_KEY", map_options, title="Combined Data", height = 600, width = 600)
source = ColumnDataSource(data=dict(
x = xs,
y = ys,
kelp = biomass_kg,
bathymetry = water_depth_m,
sst = sst,
species = species,
critical_species_distance = critical_species_distance,
county = county,
county_distance = county_distance,
pretected_areas = pretected_areas,
pretected_areas_distance = pretected_areas_distance,
estab = estab,
avg_emp = avg_emp,
qcew = qcew,
unemployment = unemployment,
ndvi = ndvi,
min_light = min_light,
mixed_l = mixed_l,
floor_temp = floor_temp,
viable = viable,
boat_launches = boat_launches,
boat_launches_distance = boat_launches_distance,
shoretype = shoretype,
shoretype_distance = shoretype_distance,
shoretype2 = shoretype2,
shoretype2_distance = shoretype2_distance,
aerial_kelp = aerial_kelp,
admin_kelp = admin_kelp))
v = ms.value
patched = Patches(xs="x", ys="y", fill_color= {"field": "kelp", "transform":color_mapper},
fill_alpha=0.8, line_color = "white", line_width = 0.7)
p.add_glyph(source, patched)
tooltip_ms = [(x.replace("@", ""), x) for x in v]
p.add_tools(HoverTool(tooltips=tooltip_ms))
return p
```

def update(attribute, old, new):

```
l.children[1] = None
l.children[1] = create_plot()
```

#Help! Still won’t update

ms.on_change(‘value’, update)

l = Column(ms, create_plot())

show(l)

``

grid_df.pkl (725 KB)