Default value for ipywidget.Dropdown() using VOILA Package

83 views Asked by At

I need to run my file.ipynb with VOILA package.

When I run this code, return this error, because the value is empty and after I select the values, run perfectly.

How can I set a default value on dropdown ? Thanks

enter image description here

import pandas as pd
import matplotlib.pyplot as plt
import ipywidgets as widgets

filename = 'data/sales_data.csv'
df = pd.read_csv(filename, index_col=0)
df.head()

df['Sales'] = df['Quantity Ordered'] * df['Price Each']

    wid_city = widgets.Dropdown(name='city')
wid_city.options = list(df.City.unique())

wid_product = widgets.Dropdown(name='product')
wid_product.options = list(df.Product.unique())

def func (city, product):
    df_tmp = df[df['City']==wid_city.value].copy()
    df_tmp = df_tmp[df_tmp['Product']==wid_product.value]
    
    ax = df_tmp.groupby(['Month']).sum()['Sales'].plot.bar()
    plt.ylabel('Sales ($)')
    plt.xlabel('Month')
    plt.show()
    
interactive_plot = widgets.interactive(func, city=wid_city, product=wid_product)

output = interactive_plot.children[-1]
output.layout.height = '500px'

interactive_plot

0

There are 0 answers