forked from chris1610/pbpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacked_bar_app.py
More file actions
49 lines (42 loc) · 1.46 KB
/
stacked_bar_app.py
File metadata and controls
49 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
""" Example Dash application accompanying the post
at http://pbpython.com/plotly-dash-intro.html
"""
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
# Read in the Excel file
df = pd.read_excel(
"https://github.com/chris1610/pbpython/blob/master/data/salesfunnel.xlsx?raw=True"
)
# Pivot the data to get it a summary format
pv = pd.pivot_table(
df,
index=['Name'],
columns=["Status"],
values=['Quantity'],
aggfunc=sum,
fill_value=0)
# Build a trace for each status that will eventual make the stacked bar
trace1 = go.Bar(x=pv.index, y=pv[('Quantity', 'declined')], name='Declined')
trace2 = go.Bar(x=pv.index, y=pv[('Quantity', 'pending')], name='Pending')
trace3 = go.Bar(x=pv.index, y=pv[('Quantity', 'presented')], name='Presented')
trace4 = go.Bar(x=pv.index, y=pv[('Quantity', 'won')], name='Won')
# Create the basic app
app = dash.Dash()
# Populate the HTML structure of the app with the graph element
app.layout = html.Div(children=[
html.H1(children='Sales Funnel Report'),
html.Div(children='''National Sales Funnel Report.'''),
dcc.Graph(
id='example-graph',
figure={
'data': [trace1, trace2, trace3, trace4],
'layout':
go.Layout(title='Order Status by Customer', barmode='stack')
})
])
# Allow the app to serve from the command line
if __name__ == '__main__':
app.run_server(debug=True)