Skip to content

Commit

Permalink
use updated app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HazelJJJ committed Jan 23, 2021
1 parent 6b4d33d commit f222bc4
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import pandas as pd
import dash_bootstrap_components as dbc

#updated data path

df = pd.read_csv(r"data/Processed/HR_employee_Attrition_editted.csv")
###Convert variables to categoriccal and reordering by label.
df['EnvironmentSatisfaction'] = df['EnvironmentSatisfaction'].astype('category').cat.rename_categories(["Bad", "Good", "Better", "Best"])
df['WorkLifeBalance']=df['WorkLifeBalance'].astype('category').cat.rename_categories(["Low", "Medium", "High", "Very High"])
df['EnvironmentSatisfaction'] = df['EnvironmentSatisfaction'].astype('category').cat.rename_categories(["1 - Bad", "2 - Good", "3 - Better", "4 - Best"])
df['WorkLifeBalance']=df['WorkLifeBalance'].astype('category').cat.rename_categories(["1 - Low", "2 - Medium", "3 - High", "4 - Very High"])
df["Department"]=df["Department"].astype('category')
df["BusinessTravel"]=df["BusinessTravel"].astype('category')
df['BusinessTravel'] = df['BusinessTravel'].cat.rename_categories(["No Travel", "Travel Frequently", "Travel Rarely"])
#df['BusinessTravel'] = df['BusinessTravel'].cat.reorder_categories(["Travel Rarely", "Travel Frequently", "No Travel"], ordered=True)
df['BusinessTravel'] = df['BusinessTravel'].cat.rename_categories(["1 - No Travel", "3 - Travel Frequently", "2 - Travel Rarely"])

# Setup app and layout/frontend
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
Expand All @@ -30,14 +29,6 @@
options=[
{'label': col, 'value': col} for col in list(set(df.Department.tolist()))],
placeholder='Select a department'),

# 'Job Role',
# dcc.Dropdown(
# id='job-widget',
# value='Sales Representative',
# options=[
# {'label': col, 'value': col} for col in set(df.JobRole.tolist())],
# placeholder='Select a job role'),

'Gender',
dcc.Dropdown(
Expand Down Expand Up @@ -65,13 +56,11 @@
id='scatter',
style={'border-width': '0', 'width': '200%', 'height': '800px'}),
)])])
#style={"height": "1000vh"}

# Set up callbacks/backend
@app.callback(
Output('scatter', 'srcDoc'),
Input('depart-widget', 'value'),
#Input('job-widget', 'value'),
Input('gender-widget', 'value'),
Input('age_slider', 'value'))

Expand All @@ -87,22 +76,22 @@ def plot_altair(depart,gender, age=18):
chart_worklife = alt.Chart(
df[(df['Department']==depart) &(df['Gender']==gender)&(df['Age']>=age[0])&(df['Age']<=age[1])],
title='Work Life Balance').mark_bar().encode(
y=alt.Y('WorkLifeBalance:O', title='', scale=alt.Scale(domain=["Low", "Medium", "High", "Very High"])),
y=alt.Y('WorkLifeBalance:O', title=''), #scale=alt.Scale(domain=["Low", "Medium", "High", "Very High"])
x=alt.X('count()', stack = 'normalize', axis=alt.Axis(format='%'), title = 'Proportion'),
color = 'Attrition'
).properties(height=200, width=250)

chart_travel = alt.Chart(
df[(df['Department']==depart) &(df['Gender']==gender)&(df['Age']>=age[0])&(df['Age']<=age[1])],
title='Business Travel Frequency').mark_bar().encode(
y=alt.Y("BusinessTravel", title="", scale=alt.Scale(domain=["No Travel", "Travel Rarely", "Travel Frequently"]),
y=alt.Y("BusinessTravel", title=""),
x=alt.X('count()', stack="normalize", axis=alt.Axis(format='%'), title='Proportion'),
color = "Attrition").properties(height=200, width=250))
color = "Attrition").properties(height=200, width=250)

chart_environment = alt.Chart(
df[(df['Department']==depart) & (df['Gender']==gender)&(df['Age']>=age[0])&(df['Age']<=age[1])],
title='Environment Satisfaction').mark_bar().encode(
y=alt.Y('EnvironmentSatisfaction', title='', scale=alt.Scale(domain=["Bad", "Good", "Better", "Best"])),
y=alt.Y('EnvironmentSatisfaction', title=''),
x=alt.X('count()', stack = 'normalize', axis=alt.Axis(format='%'), title = 'Proportion'),
color='Attrition').properties(height=200, width=250)

Expand Down

0 comments on commit f222bc4

Please sign in to comment.