Amen_90
Amen_90

Reputation: 350

Holoviews charts not updating on widget selection

I copied the code below from a separate post on creating widgets that update plots based on the selection:

# import libraries
import numpy as np
import pandas as pd

import hvplot
import hvplot.pandas

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

import panel as pn


# create sample data
df = pd.DataFrame({
    'col1': np.random.rand(30),
    'col2': np.random.normal(size=30),
    'category_col': np.random.choice(['category1', 'category2'], size=30)
})

# create widget to select category
category = pn.widgets.Select(options=['category1', 'category2'])

# function that returns a plot depending on the category selected
@pn.depends(category)
def get_plot(category):
    df_selected = df[df['category_col'] == category]
    plot = df_selected.hvplot.scatter(x='col1', y='col2')
    return plot

# show dashboard with selection widget and dynamic plot
pn.Column(
    pn.Row(category),
    get_plot,
)

# get value of current selected category
category.value

However, for me the charts do not update when the selection is made. Does anyone know what is going on here? I'm trying to execute this in a Jupyter Lab notebook on my local machine, no server. I'm running the following versions of these libraries:

holoviews: 1.13.3 hvplot: 0.6.0 panel: 0.9.7

Any insight would be greatly appreciated!

Kind regards

Upvotes: 0

Views: 1200

Answers (1)

James A. Bednar
James A. Bednar

Reputation: 3255

That code works fine for me in classic notebook using the same versions (holoviews: 1.13.3 hvplot: 0.6.0 panel: 0.9.7). Have you installed the JupyterLab extension? https://panel.holoviz.org/#installation

Upvotes: 1

Related Questions