hvplot
hvplot copied to clipboard
hvplot and panel when combined are not clearing the plot between events
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.
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.
Any idea on how I can get a new histogram after selecting from the drop-down?
Maybe add .opts(shared_axes=False)
after each .bar()
? I may be confused, but I think it's trying to link axes that you want to keep separate.
I can reproduce this issue, and confirm that the suggested workaround - bar().opts(shared_axes=False)
- fixes the issue in the example app. Still marking this issue as a bug as this is an unexpected behavior that is difficult to fix without some advanced HoloViews knowledge.
Noting that this bug only appears with Bokeh.