-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
291 lines (276 loc) · 13.9 KB
/
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import dash
import dash_bootstrap_components as dbc
from dash import html, dcc
import plotly.express as px
import pandas as pd
from dash.dependencies import Input, Output, State
import os
import flask
app = dash.Dash(__name__)
server = app.server
# Create the scatter graph
data = pd.read_csv('data.csv')
mixed_fig = px.scatter(
data,
x='ssc_p',
y='degree_p',
color='degree_t',
marginal_y='violin',
marginal_x='box',
)
mixed_fig.update_layout(showlegend=False)
scatter_fig = px.scatter(
data,
x='degree_p',
y='salary',
color='gender',
)
scatter_fig.update_layout(showlegend=False) # Remove the legend from the scatter plot
app.layout = html.Div(
style={'background-color': '#E3F4F4', 'display': 'flex', 'height': '100vh', 'margin': '0 0 0 -15px'},
children=[
html.Div(
style={'width': '320px', 'height': '590px', 'border': '1px solid #ddd', 'border-radius': '10px', 'margin': '10px', 'background-color': 'white', 'margin-right': '5px', 'padding': '20px', 'text-align': 'center', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)'},
children=[
# Side tab title
html.Div(
style={'padding': '10px', 'border-bottom': '2px solid white', 'background-color': 'white'},
children=[
html.H3('Our Products', style={'color': '#2c3e50', 'margin': '0', 'font-family': 'Arial'}),
]
),
# Button 1
html.A('Home Page', href='/', style={'background-color': 'white', 'display': 'block', 'margin-bottom': '20px', 'padding': '15px', 'color': '#2980b9', 'text-decoration': 'none', 'font-family': 'Arial', 'font-size': '18px', 'line-height': '24px', 'border': '1px solid #ddd', 'outline': 'none', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)'}),
# Button 2
html.A('PDF Report', id='pdf-link', href='/pdf', style={'background-color': 'white', 'display': 'block', 'margin-bottom': '20px', 'padding': '15px', 'color': '#2980b9', 'text-decoration': 'none', 'font-family': 'Arial', 'font-size': '18px', 'line-height': '24px', 'border': '1px solid #ddd', 'outline': 'none', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)'})
]
),
html.Div(
style={'flex': '1', 'padding': '0px 0px', 'display': 'flex', 'flex-direction': 'column', 'align-items': 'flex-end', 'justify-content': 'top', 'margin': '10px'},
children=[
html.Div(
style={'display': 'flex', 'justify-content': 'flex-end', 'margin-bottom': '20px'},
children=[
html.Div(
html.Img(src=app.get_asset_url('1.svg'), width='180px', height='55px'), style={'width': '210px','object-fit': 'cover', 'padding':'10px', 'margin': 'auto', 'margin-left': '10px', 'margin-right': '10px', 'border': '1px solid white', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'}
),
html.Div(
style={'width': '300px', 'margin-left': '15px', 'margin-right': '10px', 'border': '1px solid white', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Genders selection', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial'}),
dcc.Dropdown(
id='gender-dropdown',
options=[
{'label': 'Male', 'value': 'M'},
{'label': 'Female', 'value': 'F'}
],
value=[],
multi=True,
placeholder='Select Genders',
style={'width': '97%', 'margin': 'auto','font-family': 'Arial'}
)
]
),
html.Div(
style={'width': '320px', 'margin-left': '15px', 'margin-right': '0px', 'border': '1px solid white', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H3('Salary Slider', style={ 'fontSize':'16px','color': '#2980b9', 'margin': '10px', 'font-family': 'Arial'}),
dcc.Slider(
id='salary-slider',
min=data['salary'].min(),
max=data['salary'].max(),
step=100000,
value=data['salary'].min(),
marks={i*1000000: f'${i}M' for i in range(0, int(data['salary'].max() / 1000000), 100)},
),
]
)
]
),
html.Div(
style={'display': 'flex', 'justify-content': 'center', 'margin-bottom': '20px'},
children=[
html.Div(
style={'width': '426.6px', 'border': '1px solid white', 'padding': '10px', 'margin-right': '10px', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Degree Types: Secondary & Graduation Percentage', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial','text-align': 'center'}),
dcc.Graph(
id='mixed-graph',
figure=mixed_fig,
config={'displayModeBar': False},
style={'width': '100%', 'height': '350px', 'object-fit': 'contain','font-family': 'Arial'}
)
]
),
html.Div(
style={'width': '426.6px', 'border': '1px solid white', 'padding': '10px', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Scatterplot: Salary, Education & Experience', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial','text-align': 'center'}),
dcc.Graph(
id='scatterplot',
figure=scatter_fig,
config={'displayModeBar': False},
style={'width': '100%', 'height': '350px', 'object-fit': 'contain','font-family': 'Arial'}
)
]
)
]
),
html.Div(
style={'display': 'flex', 'justify-content': 'center', 'margin-bottom': '0px'},
children=[
html.Div(
style={'width': '270px', 'border': '1px solid white', 'padding': '10px', 'margin-right': '5px', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Degree types removal', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial'}),
dcc.Dropdown(
id='remove-degree-dropdown',
options=[
{'label': 'Sci&Tech', 'value': 'Sci&Tech'},
{'label': 'Comm&Mgmt', 'value': 'Comm&Mgmt'},
{'label': 'Others', 'value': 'Others'}
],
value=[],
multi=True,
placeholder='Remove Degree Categories',
style={'width': '100%','font-family': 'Arial'}
)
]
),
html.Div(
style={'width': '270px', 'margin-left': '10px', 'margin-right': '10px', 'padding': '10px', 'border': '1px solid white', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Work Experience Removal', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial'}),
dcc.Dropdown(
id='remove-workex-dropdown',
options=[
{'label': 'Yes', 'value': 'Yes'},
{'label': 'No', 'value': 'No'}
],
value=[],
multi=True,
placeholder='Remove Workex',
style={'width': '100%','font-family': 'Arial'}
)
]
),
html.Div(
style={'width': '270px', 'border': '1px solid white', 'margin-left': '5px', 'padding': '10px', 'border-radius': '10px', 'box-shadow': '2px 2px 5px 0px rgba(0,0,0,0.3)', 'background-color': 'white'},
children=[
html.H4('Toggle Trendline', style={'color': '#2980b9', 'margin': '10px', 'font-family': 'Arial'}),
dcc.RadioItems(
id='toggle-trendline',
options=[
{'label': 'Scatter', 'value': 'scatter'},
{'label': 'Trendline', 'value': 'trendline'}
],
value='scatter',
labelStyle={'display': 'inline-block', 'margin-right': '10px','font-family': 'Arial'}
)
]
)
]
)
]
)
]
)
@app.server.route('/pdf')
def serve_pdf():
pdf_path = 'assets/1.pdf'
return flask.send_file(pdf_path, attachment_filename='1.pdf')
@app.callback(
Output('salary-range-output', 'children'),
Input('salary-slider', 'value')
)
def update_salary_range_output(salary):
min_salary = '$0' # Replace 0 with the actual minimum value
max_salary = '$1000000' # Replace 100000 with the actual maximum value
return html.Div(
[
html.Div(f'{min_salary}', style={'font-family': 'Arial','color': '#2980b9', 'textAlign': 'left', 'marginTop': '-25px','marginLeft': '15px'}),
html.Div(f'{max_salary}', style={'font-family': 'Arial','color': '#2980b9', 'textAlign': 'right', 'marginTop': '-25px','marginRight': '10px'})
],
style={'display': 'flex', 'justifyContent': 'space-between'}
)
@app.callback(
Output('mixed-graph', 'figure'),
Output('scatterplot', 'figure'),
Input('gender-dropdown', 'value'),
Input('salary-slider', 'value'),
Input('remove-degree-dropdown', 'value'),
Input('remove-workex-dropdown', 'value'),
Input('toggle-trendline', 'value')
)
def update_graphs(gender_value, salary_value, remove_degree_value, remove_workex_value, trendline_value):
filtered_data = data.copy()
# Filter by gender
if gender_value:
filtered_data = filtered_data[filtered_data['gender'].isin(gender_value)]
# Filter by salary
filtered_data = filtered_data[filtered_data['salary'] >= salary_value]
# Remove selected degree types
if remove_degree_value:
filtered_data = filtered_data[~filtered_data['degree_t'].isin(remove_degree_value)]
# Remove selected workex values
if remove_workex_value:
filtered_data = filtered_data[~filtered_data['workex'].isin(remove_workex_value)]
mixed_fig = px.scatter(
filtered_data,
x='ssc_p',
y='degree_p',
color='degree_t',
marginal_y='violin',
marginal_x='box',
trendline='ols' if trendline_value == 'trendline' else None
)
# Update mixed_fig layout
mixed_fig.update_layout(
showlegend=False,
xaxis_title='Secondary Education Percentage',
yaxis_title='Graduation Degree Percentage',
xaxis=dict(
title=dict(
font=dict(
family='Arial'
)
)
),
yaxis=dict(
title=dict(
font=dict(
family='Arial'
)
)
)
)
scatter_fig = px.scatter(
filtered_data,
x='degree_p',
y='salary',
color='gender',
trendline='ols' if trendline_value == 'trendline' else None
)
# Update scatter_fig layout
scatter_fig.update_layout(
showlegend=False,
xaxis_title='Secondary Education Percentage',
yaxis_title='Salary',
xaxis=dict(
title=dict(
font=dict(
family='Arial'
)
)
),
yaxis=dict(
title=dict(
font=dict(
family='Arial'
)
)
)
)
return mixed_fig, scatter_fig
if __name__ == '__main__':
app.run_server(debug=True)