Py.Cafe

amward/

dash-org-chart

Company Organizational Hierarchy Visualization

DocsPricing
  • app.py
  • requirements.txt
app.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

from dash import Dash, dcc, html
import plotly.graph_objects as go

app = Dash(__name__)


# Data from the input
rowData = [
    {"orgHierarchy": ["Erica Rogers"], "jobTitle": "CEO", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett"], "jobTitle": "Exec. Vice President", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Esther Baker"], "jobTitle": "Director of Operations", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Esther Baker", "Brittany Hanson"], "jobTitle": "Fleet Coordinator", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Esther Baker", "Brittany Hanson", "Leah Flowers"], "jobTitle": "Parts Technician", "employmentType": "Contract"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Esther Baker", "Brittany Hanson", "Tammy Sutton"], "jobTitle": "Service Technician", "employmentType": "Contract"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Esther Baker", "Derek Paul"], "jobTitle": "Inventory Control", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Francis Strickland"], "jobTitle": "VP Sales", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Francis Strickland", "Morris Hanson"], "jobTitle": "Sales Manager", "employmentType": "Permanent"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Francis Strickland", "Todd Tyler"], "jobTitle": "Sales Executive", "employmentType": "Contract"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Francis Strickland", "Bennie Wise"], "jobTitle": "Sales Executive", "employmentType": "Contract"},
    {"orgHierarchy": ["Erica Rogers", "Malcolm Barrett", "Francis Strickland", "Joel Cooper"], "jobTitle": "Sales Executive", "employmentType": "Permanent"},
]

# Extracting the necessary components for the treemap
labels = []
parents = []
job_titles = []
employment_types = []

for row in rowData:
    hierarchy = row["orgHierarchy"]
    for i in range(len(hierarchy)):
        if hierarchy[i] not in labels:
            labels.append(hierarchy[i])
            job_titles.append(row["jobTitle"] if i == len(hierarchy) - 1 else "")
            employment_types.append(row["employmentType"] if i == len(hierarchy) - 1 else "")
            
            # The root node Erica Rogers has no parent
            if i == 0:
                parents.append("")
            else:
                parents.append(hierarchy[i - 1])

# Creating the treemap
fig = go.Figure(go.Treemap(
    labels=labels,
    parents=parents,
    text=job_titles,
    hoverinfo='label+text+value+percent entry',
    customdata=employment_types,
    textinfo="label+text",
    marker=dict(colorscale='Blues')
))

# Update layout
fig.update_layout(
    title="Company Organizational Hierarchy",
    margin=dict(t=50, l=25, r=25, b=25)
)


app.layout = html.Div([
    dcc.Graph(figure=fig)
])

if __name__ == '__main__':
    app.run(debug=True)