How can I get HoloViews plots or Hvplot working on Databricks?
The generated plot should also keep all interactivity.

- 10,986
- 5
- 51
- 96
3 Answers
The Bokeh file_html
will return HTML+JS code to provide interactive plot of your data. The total HTML must be less than 20MB. Your data needs to be inline to your HTML otherwise you may run into CSRF errors. Ensure you've installed python holoviews
, bokeh
, and hvplot
packages. Example:
import math
import numpy as np
import pandas as pd
import holoviews as hv
from bokeh.embed import components, file_html
from bokeh.resources import CDN
hv.extension('bokeh')
import hvplot
renderer = hv.renderer('bokeh').instance(fig='html', holomap='auto')
# see https://github.com/ioam/holoviews/issues/1819
def displayHoloviews(hv_plot, html_name="plot.html", width=1000, height=600, renderer=renderer):
plot = renderer.get_plot(hv_plot).state
setattr(plot, 'plot_width', width)
setattr(plot, 'plot_height', height)
displayHTML(file_html(plot, CDN, html_name))
index = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=index, columns=list('ABCD')).cumsum()
displayHoloviews(hvplot.hvPlot(df).line(y=['A','B','C','D']))

- 10,986
- 5
- 51
- 96

- 1,035
- 8
- 17
You can simply use
import holoviews as hv
your_plot = hv.Points(np.random.multivariate_normal((0,0), [[0.1, 0.1], [0.1, 1.0]], (1000,)))
renderer = hv.renderer("bokeh")
displayHTML(renderer.html(your_plot))
However, AFAIU using displayHTML()
prevents the scalability features of decimate()
or datashader
, it will only show the initially rendered version of the plot. This is also the case for the other answers, and I’m not sure a solution preserving scalability on DataBricks currently exists (I’m greatly interested in such a solution !).

- 6,976
- 4
- 60
- 76
You can save your HoloViews plot as an HTML file and then use displayHTML().
Solution was inspired by this blog:
https://anitagraser.com/2020/02/02/first-working-movingpandas-setup-on-databricks/
The disadvantage of this method is that your html file shouldn't get too large otherwise you could get problems saving the notebook.
Here's a working example:
# import libraries
import numpy as np
import pandas as pd
import holoviews as hv
import hvplot.pandas
# create sample date
df = pd.DataFrame(np.random.rand(50, 2), columns=['col1', 'col2'])
df['col3'] = np.random.randint(0, 2, 50)
# create holoviews scatter plot
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2', groupby='col3')
# save scatter plot as html
hv.save(hv_scatter, 'hv_scatter.html')
# assign html file to variable
with open('hv_scatter.html', 'r') as html_file:
html_scatter = html_file.read()
# display scatter plot
displayHTML(html_scatter)
As an alternative you could also render your plot as a Bokeh plot and then use the example of this notebook:
https://docs.databricks.com/notebooks/visualizations/bokeh.html

- 10,986
- 5
- 51
- 96