So here is a reproductible example based on [https://holoviews.org/gallery/demos/bokeh/choropleth_data_link.html#demos-bokeh-gallery-choropleth-data-link]:
import holoviews as hv
from holoviews import opts
from holoviews.plotting.links import DataLink
hv.extension('bokeh')
from bokeh.sampledata.us_counties import data as counties
from bokeh.sampledata.unemployment import data as unemployment
# Generate dummy data
data2 = {}
data3 = {}
for ind, keys in enumerate(list(unemployment.keys())):
data2[keys] = unemployment[keys]+ind/10
data3[keys] = unemployment[keys]-ind/10
print(list(data2.items())[0:3])
counties = [dict(county, Unemployment=unemployment[cid], Data2=data2[cid], Data3=data3[cid])
for cid, county in counties.items()
if county["state"] == "tx"]
def map_and_table(counties,var='Unemployment'):
county_data = [(county['detailed name'], county[var]) for county in counties]
choropleth = hv.Polygons(counties, ['lons', 'lats'], [('detailed name', 'County'), var])#, label='Texas ' + var)
table = hv.Table(county_data, [('detailed name', 'County'), var])
# Link the choropleth and the table
DataLink(choropleth, table)
layout = choropleth + table
layout.opts(
opts.Table(height=428),
opts.Polygons(width=500, height=500, tools=['hover', 'tap'], xaxis=None,
yaxis=None, color_index=var))
return layout
layout=map_and_table(counties,var='Data2')
layout
statistics = ('Unemployment','Data2','Data3')
# get a map object
layout_dict = {stat: map_and_table(counties,var=stat)[0] for stat in statistics}
kdims = [hv.Dimension(('statistics', 'Statistics'))]
holomaps = hv.HoloMap(layout_dict, kdims=kdims)
# get a table object
layout_dict = {stat: map_and_table(counties,var=stat)[1] for stat in statistics}
kdims = [hv.Dimension(('statistics', 'Statistics'))]
holotables = hv.HoloMap(layout_dict, kdims=kdims)
# Link both object
DataLink(holomaps, holotables)
holomapwithtable = holomaps + holotables
holomapwithtable
This generated a figure similar to this one:
If the datalink is working properly between the map and the table, the hover text is not changing when selecting different statistics.
Do you know how I could fix that?
The notebook can be accessed here: https://nbviewer.jupyter.org/urls/dl.dropbox.com/s/amtbmtd6j6s3ts0/choropleth_data_link_holo.ipynb
Thank you!