0

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

import panel.widgets as pnw
import panel as pn
pn.extension()

# some data cleansing yields a df containing the data of interest


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

def histogram_of_variant_revenue(selected_product=None):
    selection = df[df["product_name"] == selected_product]
    selection["revenue"] = selection["revenue"].astype(float)
    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]
    selection["customers"] = selection["customers"].astype(float)
    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 suggestion.

First run

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?

Second run

user2302244
  • 843
  • 2
  • 11
  • 27

0 Answers0