holoviz / holoviz/hvplot

hvplot and panel when combined are not clearing the plot between events

Open
#914 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

I am trying to establish a dashboard using jupyter, panel and hvplot. This is the code snippet.

```
import pandas as pd
import panel.widgets as pnw
import panel as pn
import hvplot.pandas
pn.extension()

# some data cleansing yields a df containing the data of interest
df = pd.DataFrame.from_records([
{"product_name": "One", "name": "One-One", "revenue": 10, "customers": 50},
{"product_name": "One", "name": "One-Two", "revenue": 20, "customers": 150},
{"product_name": "Two", "name": "Two-One", "revenue": 30, "customers": 250},
{"product_name": "Two", "name": "Two-Two", "revenue": 40, "customers": 350},
])

products = df["product_name"].drop_duplicates()

def histogram_of_variant_revenue(selected_product=None):
selection = df[df["product_name"] == selected_product]
print(selection.shape)
return selection[["name", "revenue"]].drop_duplicates().set_index("name").hvplot.bar()

def histogram_of_variant_customers(selected_product=None):
selection = df[df["product_name"] == selected_product]
print(selection.shape)
return selection[["name", "customers"]].drop_duplicates().set_index("name").hvplot.bar()

selected_product = pnw.Select(name='Product', options=sorted(list(products)))
customers = pn.bind(histogram_of_variant_customers, selected_product)
revenue = pn.bind(histogram_of_variant_revenue, selected_product)
combined_panel = pn.Column(selected_product, customers, revenue)
combined_panel
```
At the default selection.
![image](https://user-images.githubusercontent.com/1669863/191322052-43bd1386-8ee9-411d-8129-6ffd5674ad45.png)
After the next use of the drop-down selection. Notice that instead of getting a new chart - the old one seems to have moved to the right and the new one placed into the figure.
![image](https://user-images.githubusercontent.com/1669863/191322426-dc0cb683-453d-4dc6-8ebd-07efc1c1c9d2.png)

Any idea on how I can get a new histogram after selecting from the drop-down?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.