I’m trying to create an interactive dashboard similar to what is shown in the 2nd example here, but I can’t get it to update the dashboard using the dropdown list
import pandas as pd
import plotly.offline as off
off.init_notebook_mode(connected=False)
df = pd.DataFrame({'col1': ['Product A','Product A','Product A','Product B','Product B','Product B','Product C','Product C','Product C'], 'col2': [3,5,2,1,3,1,2,3,2],
'col3': ['Client X','Client Y','Client Z','Client X','Client Y','Client Z','Client X','Client Y','Client Z']})
Product = df['col1']
Quantity = df['col2']
Client = df['col3']
aggs = df['col3'].unique()
agg = []
agg_func = []
for i in range(0, len(aggs)):
agg = dict(
args=['transforms[0].value',aggs[i]],
label=aggs[i],
method='restyle'
)
agg_func.append(agg)
plot_data = [dict(
type = 'bar',
x = Product,
y = Quantity,
mode = 'markers',
transforms = [dict(
type = 'aggregate',
groups = Product,
aggregations = [dict(
target = 'y', func = 'sum', enabled = True)
]
)]
)]
layout = dict(
title = '<b>Plotly Aggregations</b><br>use dropdown to change aggregation',
xaxis = dict(title = 'Product',autorange = True),
yaxis = dict(title = 'Quantity',autorange = True),
updatemenus = [dict(
x = 0.85,
y = 1.15,
xref = 'paper',
yref = 'paper',
yanchor = 'top',
active = 1,
showactive = False,
buttons = agg_func
)]
)
off.iplot({'data': plot_data,'layout': layout}, validate=False)
Your help is much appreciated