Plotting holoviews plot


I would like to plot an interactive Holoviews plot with streamlit.
Is this possible? If so, how can I can do this?

Here’s an example of generating a holoviews (bokeh) plot with hvplot. The example of the line_chart works, but displaying my interactive holoviews plot doesn’t work.

# import libraries
import streamlit as st

import numpy as np
import pandas as pd

import hvplot
import hvplot.pandas

import holoviews as hv
hv.extension('bokeh', logo=False)

# create sample data
def get_data():
    return pd.DataFrame(data=np.random.normal(size=[50, 2]), columns=['col1', 'col2'])

df = get_data()

# streamlit plotting works

# creating a holoviews plot
nice_plot = df.hvplot(kind='scatter')

# this doesn't work unfortunately. How can i show 'nice_plot'

Hi @SandervandenOord! Welcome to the Streamlit community! :hugs:

I believe the incantation you’re looking for is:

st.bokeh_chart(hv.render(nice_plot, backend='bokeh'))

Also, since hv.render(..., backend='bokeh') has type bokeh.plotting.figure.Figure, you could also just use:

st.write(hv.render(nice_plot, backend='bokeh'))

Please let us know if you have further questions!


@Adrien_Treuille thank you for that! I wonder if you all might be open to a top-level API call, such as st.hvplot(nice_plot) that automagically wraps hv.render in there? If so, I’m happy to write the PR that makes this happen.

1 Like

Thanks for the offer — that would be amazing!

Depending on how much code this turns out to be, though, a good strategy would be to send out working sketch of the solution in a PR with the WIP label, so we can discuss architecture there before you do too much coding. Up to you, though.

1 Like

This is a great idea, but st.hvplot has a bit of a name conflict with the package hvplot. Perhaps st.hv would be enough?

For a more general solution, I just opened a new issue with the suggestion that streamlit look on objects for a particular method and use that if provided.

1 Like

@jsignell I think your idea is even better than the one I thought of!