HoloViews Tabular Data Take Two

In [1]:
from pathlib import Path
import os
In [50]:
from bokeh.io import output_notebook
from bokeh.embed import autoload_static
from bokeh.resources import CDN
from dotenv import load_dotenv
from holoviews import opts
from tabulate import tabulate
import holoviews
import numpy
import pandas
In [36]:
output_notebook()
Loading BokehJS ...
In [37]:
load_dotenv(".env")
Out[37]:
True
In [38]:
holoviews.extension("bokeh")
In [39]:
path = Path(os.environ.get("DISEASES")).expanduser()
assert path.is_file()
with path.open() as reader:
    diseases = pandas.read_csv(path)
In [40]:
diseases.head()
Out[40]:
Year Week State measles pertussis
0 1928 1 Alabama 3.67 NaN
1 1928 2 Alabama 6.25 NaN
2 1928 3 Alabama 7.95 NaN
3 1928 4 Alabama 12.58 NaN
4 1928 5 Alabama 8.03 NaN
In [41]:
key_dimensions = "Year State".split()
value_dimensions = [("measles", "Measles Incidence"), ("pertussis", "Pertusis Incidence")]
dataset = holoviews.Dataset(diseases, key_dimensions, value_dimensions)
In [42]:
dataset = dataset.aggregate(function=numpy.mean)
In [43]:
dataset
Out[43]:
:Dataset   [Year,State]   (measles,pertussis)
In [48]:
layout = (dataset.to(holoviews.Curve, "Year", "measles")
          + dataset.to(holoviews.Curve, "Year", "pertussis")).cols(1)
plot = layout.options(opts.Curve(width=600, height=300, framewise=True, tools=["hover"]))
plot
Out[48]:

So if you looked at this in a jupyter notebook with a running server there would be the plot above with working dropdown menus. But otherwise nope.

In [49]:
holoviews.save(plot, "diseases.html")
In [51]:
renderer = holoviews.renderer("bokeh")
figure = renderer.get_plot(plot).state
javascript, tag = autoload_static(figure, CDN, "diseases.js")
In [52]:
print(tag)
<script src="diseases.js" id="5e346ec9-db34-4143-bfa3-a2fe8d2e0da0"></script>
In [53]:
%%HTML
<script src="diseases.js" id="5e346ec9-db34-4143-bfa3-a2fe8d2e0da0"></script>
In [56]:
with open("../../files/posts/libraries/holoviews-tabular-data-take-two/diseases.js", "w") as writer:
    writer.write(javascript)

Okay, so weirdly, using autoload_static seems to be what's breaking it, because even the javascript exported by this notebook doesn't have the dropdown menu.

In [ ]: