Hi All,
I have a simple bar-plot that uses 3 dropdown menus that while it selects data-points, it does not update/plot values correctly. For example, when I select year=2013, state=New York and regulator=SEC, it should be showing me a total of 18 but instead shows 7, stocks=11 but it shows 6⦠etc⦠Can anyone advise on what may be wrong in the code? Sample dataset and code below. Thanks!
DummyData = https://drive.google.com/file/d/1SgaM9OKdsR1QHbp_qFw1dEOT_hc_bdeP/view?usp=sharing
use_date = widgets.Dropdown(
options=list(df['Year Month'].unique()),
description='Date : ',
value=2012,
)
container = widgets.HBox(children=[use_date])
reg = widgets.Dropdown(
options=list(df['Regulator'].unique()),
value='[Total]',
description='Regulator :',
)
origin = widgets.Dropdown(
options=list(df['State'].unique()),
value='Alabama',
description='Filing State :',
)
# Assign an emptry figure widget with two traces
trace1 = go.Bar(x=df.groupby(by="Industry").count()["Year Month"], name='SARs Filings', orientation='v')
g = go.FigureWidget(data=[trace1],
layout=go.Layout(
barmode='group',
hovermode="closest",
title=dict(
text='SAR Filings by State and Product'
)
))
def validate():
if origin.value in df['State'].unique() and reg.value in df['Regulator'].unique() :
return True
else:
return False
def response(change):
if validate():
if use_date.value:
filter_list = [i and j and k for i, j, k in
zip(df['Year Month'] == use_date.value,
df['Regulator'] == reg.value,
df['State'] == origin.value)]
temp_df = df[filter_list]
else:
filter_list = [i and j for i, j in
zip(df['Regulator'] == '[Total]', df['State'] == origin.value)]
temp_df = df[filter_list]
x = temp_df['Product']
with g.batch_update():
g.data[0].x = x
g.layout.xaxis.title = 'SARs Filing Type'
g.layout.yaxis.title = 'Number of Filings'
origin.observe(response, names="value")
reg.observe(response, names="value")
use_date.observe(response, names="value")
container2 = widgets.HBox([origin, reg])
widgets.VBox([container,
container2,g])