I want to convert my plot to an interactive html, but not save it.
I am using Databricks and this needs an html file to display plots from Holoviews as well as Plotly.
But i get this error when I render my plot to html:
expected Resources or a pair of optional Resources, got 'CDN'
What should I change to my code? Are there other ways of getting (interactive) html?
Here’s my code:
import numpy as np
import pandas as pd
import holoviews as hv
import hvplot.pandas
data = np.random.rand(50, 2)
df = pd.DataFrame(data, columns=['col1', 'col2'])
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2')
renderer = hv.renderer('bokeh')
# this gives the error
html_scatter = renderer.html(hv_scatter)
Could you file an issue about this in HoloVIews? For now just provide the correct resources:
html_scatter = renderer.html(hv_scatter, resources='cdn')
Ok, will make an issue
So your solution works for:
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2')
html_scatter = renderer.html(hv_scatter, resources='cdn')
But when I try it with a groupby
then I get a warning:
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2', groupby='col3')
html_scatter = renderer.html(hv_scatter, resources='cdn')
WARNING:bokeh.embed.util:
You are generating standalone HTML/JS output, but trying to use real Python
callbacks (i.e. with on_change or on_event). This combination cannot work.
Only JavaScript callbacks may be used with standalone output. For more
information on JavaScript callbacks with Bokeh, see:
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html
Alternatively, to use real Python callbacks, a Bokeh server application may
be used. For more information on building and running Bokeh applications, see:
https://docs.bokeh.org/en/latest/docs/user_guide/server.html
But when I try it with a groupby then I get a warning:
A groupby in hvplot returns a DynamicMap which cannot ordinarily be exported to HTML as is. You’ll have to use some variation on:
stringio = StringIO()
pn.panel(hv_obj).save(stringio, embed=True)
stringio.seek(0)
html = stringio.read()
Alternatively add dynamic=False to your hvplot call:
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2', groupby='col3', dynamic=False)