pythonvisual-studioholoviewsholovizpanel-pyviz

How do i get my interactive Holoviews graph to display in Visual Studio (without Jupyter)?


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?


Solution

  • 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))