I'm mainly using Jupyter Notebook / Lab when using Holoviews for interactive plotting.
How do I make Visual Studio display my interactive graphs and panels, without using the Interactive Jupyter inside Visual Studio?
Asked
Active
Viewed 3,434 times
3

Sander van den Oord
- 10,986
- 5
- 51
- 96
2 Answers
4
Easiest solution is to set bokeh as backend of the renderer and then use bokeh.render.show(). This will open your holoviews plot in the browser:
hv.extension('bokeh')
from bokeh.plotting import show
show(hv.render(your_holoviews_plot))
Full working example:
# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
# setting bokeh as backend
hv.extension('bokeh')
# going to use show() to open plot in browser
from bokeh.plotting import show
# create some sample data
data = np.random.normal(size=[50, 2])
df = pd.DataFrame(
data=data,
columns=['col1', 'col2'],
)
# using hvplot here to create a holoviews plot
# could have also just used holoviews itself
plot = df.hvplot(kind='scatter', x='col1', y='col2')
# use show() from bokeh
show(hv.render(plot))

Sander van den Oord
- 10,986
- 5
- 51
- 96
3
One way to use interactive graphs from Holoviews etc in Visual Studio is executing code to show the graph in your browser (which Holoviews is meant for).
The example below puts your Holoviews graph in a Panel and starts a Bokeh server.
It opens a new tab on your browser and shows your graph.
# library imports
import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh', logo=False)
import panel as pn
# create sample data
data = np.random.normal(size=[50, 2])
df = pd.DataFrame(data, columns=['col1', 'col2'])
# create holoviews graph
hv_plot = hv.Points(df)
# display graph in browser
# a bokeh server is automatically started
bokeh_server = pn.Row(hv_plot).show(port=12345)
# stop the bokeh server (when needed)
bokeh_server.stop()

Sander van den Oord
- 10,986
- 5
- 51
- 96
-
The `hv_plot` could also be created like in the another answer; with `hv_plot = df.hvplot(kind="scatter", x="col1", y="col2")`. Then, I believe importing `holoviews` is not needed. Not sure what `hv.extension('bokeh', logo=False)` does, but I seem not need it (is it related to Jupyter notebooks?). – Niko Föhr Mar 14 '22 at 19:23
-
yeah, hv.extension() is not really necessary. And, since the question mentioned HoloViews instead of hvplot, I created a plot with holoviews instead of hvplot. But both would be fine here :) – Sander van den Oord Mar 15 '22 at 10:56