{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install dash","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:16.203764Z","iopub.execute_input":"2022-07-17T13:25:16.204201Z","iopub.status.idle":"2022-07-17T13:25:31.234543Z","shell.execute_reply.started":"2022-07-17T13:25:16.204106Z","shell.execute_reply":"2022-07-17T13:25:31.233195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install dash_bootstrap_components","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:31.238562Z","iopub.execute_input":"2022-07-17T13:25:31.238920Z","iopub.status.idle":"2022-07-17T13:25:41.772204Z","shell.execute_reply.started":"2022-07-17T13:25:31.238889Z","shell.execute_reply":"2022-07-17T13:25:41.771075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install jupyter_dash","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:41.774215Z","iopub.execute_input":"2022-07-17T13:25:41.774610Z","iopub.status.idle":"2022-07-17T13:25:52.768307Z","shell.execute_reply.started":"2022-07-17T13:25:41.774571Z","shell.execute_reply":"2022-07-17T13:25:52.767150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# importing necessary library \n\nimport pandas as pd\nimport plotly.graph_objects as go\nimport dash\nimport dash_core_components as dcc\nimport dash_html_components as html\nfrom dash import Input,Output\nimport plotly.express as px\nimport dash_bootstrap_components as dbc\nimport pycountry\nimport pandas_datareader.data as web\nimport datetime\nfrom jupyter_dash import JupyterDash\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:52.771122Z","iopub.execute_input":"2022-07-17T13:25:52.771744Z","iopub.status.idle":"2022-07-17T13:25:56.491427Z","shell.execute_reply.started":"2022-07-17T13:25:52.771702Z","shell.execute_reply":"2022-07-17T13:25:56.490493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= pd.read_csv('/kaggle/input/software-professional-salaries-2022/Salary_Dataset_with_Extra_Features.csv')\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:56.492607Z","iopub.execute_input":"2022-07-17T13:25:56.493379Z","iopub.status.idle":"2022-07-17T13:25:56.559201Z","shell.execute_reply.started":"2022-07-17T13:25:56.493339Z","shell.execute_reply":"2022-07-17T13:25:56.558222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# supporting functions  ( thig function will help our main function in app for plotting graphs)\n\n#function to create plotly table\ndef Table(dff):  \n    \n    data= dff['Company Name'].value_counts().head(20)\n\n\n    fig= go.Figure()\n    fig.add_trace(go.Table( columnwidth = [15,6],\n\n            header=dict(values=['<b> Company <b>','<b>Number of<br>Employees<b>'],  \n                        line_color='black',font=dict(color='black',size= 14),height=30,\n                        fill_color='lightskyblue',\n                        align=['left','center']),\n                cells=dict(values=[data.index,data.values],\n                       fill_color='lightcyan',line_color='grey',\n                           font=dict(color='black', family=\"Lato\", size=15),\n                       align='left')))\n    fig.update_layout( \n                      title ={'text': \"<b style:'color:blue;'>Top 20 Companys </b>\", 'font': {'size': 16}},title_x=0.5,\n\n       # title_font_family=\"Times New Roman\",\n        title_font_color=\"slategray\",margin=dict(l=0, r=0, b=0,t=27))  \n    return fig\n\n\ndef donut(data):\n    fig=  px.pie(names=data.index , values= data.values,hole=.5,color_discrete_sequence=px.colors.sequential.Blues_r,height=350)\n    fig.update_layout(\n                        autosize=True,legend_orientation=\"h\",\n                  legend=dict(x=0.09, y=0., traceorder=\"normal\"),\n                        title ={'text': \"<b style:'color:blue;'>Employment Status \"\n                                , 'font': {'size': 16}},title_x=0.5,title_y=0.97,\n                        #title_font_family=\"Times New Roman\",\n                        title_font_color=\"slategray\",\n                        font_color='slategray',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                   # yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n                paper_bgcolor='rgba(0,0,0,0)',\n                        plot_bgcolor='lightblue' \n     ,margin=dict( b=0,l=12,r=12)\n    )\n    #fig.update_traces(showlegend=False)\n    return fig\n\ndef salary_meter(data):\n    \n    fig= go.Figure()\n    fig.add_trace(\n        go.Indicator(\n            {\n            'mode': 'gauge+number', \n            'number': {'font': {'color': '#1C4E80'}}, \n            'gauge':{'bar': {'color': 'skyblue'},'axis':{'range': [None, 100000]}},\n             \n            #'delta' :{\"reference\": 100000, \"valueformat\": \".0f\"},\n            'value':  data['Salary'].mean() /10\n       #     'title' :{'text': 'Rating', 'font': {'size': 20}}\n             })\n        )\n    fig.update_layout(height=170,width=350,margin=dict(t=50,b=10))\n    fig.update_layout(title ={'text': 'Average Salary', 'font': {'size': 20}},title_x=0.51,title_y=0.97,title_font_color='dimgray')\n    \n    return fig\n\ndef location_sorting(df):\n    location_count= df.groupby('Location')['Job Roles'].count()\n    new_df = pd.DataFrame({'Location':location_count.index , 'Count':location_count.values})\n    new_df.reset_index(drop=True,inplace=True)\n    return new_df.sort_values('Count',ascending=False)\n\ndef meter(data):\n\n    fig= go.Figure()\n    fig.add_trace(\n        go.Indicator(\n            {\n            'mode': 'gauge+number+delta', \n            'number': {'font': {'color': '#1C4E80'}}, \n            'gauge':{'bar': {'color': 'skyblue'},'axis':{'range': [1, 5]}},\n        \n            'value':  data['Rating'].mean()\n       #     'title' :{'text': 'Rating', 'font': {'size': 20}}\n             })\n        )\n    fig.update_layout(height=170,width=350,margin=dict(t=50,b=10))\n    fig.update_layout(title ={'text': 'Average Rating', 'font': {'size': 21}},title_x=0.49,title_y=0.97,title_font_color='dimgray')\n    \n    return fig\n\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:25:56.560815Z","iopub.execute_input":"2022-07-17T13:25:56.561203Z","iopub.status.idle":"2022-07-17T13:25:56.582452Z","shell.execute_reply.started":"2022-07-17T13:25:56.561165Z","shell.execute_reply":"2022-07-17T13:25:56.581137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# dash plotly App \n\n\napp =JupyterDash(__name__,external_stylesheets=[dbc.themes.SANDSTONE]\n            \n              , meta_tags=[{'name': 'viewport',\n                            'content': 'width=device-width, initial-scale=1.0'}])\n\n#########################################################  Frontend :App Layout  ############################################################################\nlist_of_job_roles=['Android developer','Backend developer','Database Administrator ','Frontend developer','IOS developer','Java developer','Mobile developer','SDE',\n 'Python developer','Web developer','Testing','All']\nlist_of_location=['Bangalore','Chennai','Hyderabad','New Delhi','Pune','Jaipur','Kerala','Kolkata','Madhya Pradesh','Mumbai','All']\ndropdown1=dcc.Dropdown(list_of_job_roles,placeholder='SDE',id='dropdown1',style= {'background-color': '#F0FFFF'},multi=False,value='All',className='dropup1')\ndropdown2=dcc.Dropdown(list_of_location,placeholder='All',id='dropdown2',style= {'background-color': '#F0FFFF'},multi=False,value='All',className='dropup2')\ncard = dbc.Card([\n                dbc.CardBody([dcc.Graph(figure={},style={'height': '118px'})\n                            ])\n                 ],className='mb-2 h-20')\ncard2 = dbc.Card([dbc.CardHeader(html.H6('Rating')),\n                dbc.CardBody([dcc.Graph(figure={},style={'height': '400px'})\n                            ])\n                 ],className='mb-2')\n\n#card1=dcc.Graph(id='rating',figure={}  )          \n#card2= dbc.Card(dbc.CardBody(  ))\nhistogram=dbc.Card([\n                dbc.CardBody([dcc.Graph(id='hist',figure={},style={'height': '370px'})\n                            ])\n                 ],className='mb-2',color= '#FCFBFC')\n\naverage_salary=dbc.Card([\n                dbc.CardBody([dcc.Graph(id='salary',figure={},style={'height': '167px'})\n                            ])\n                 ],className='mb-1 ')\n\nrating =dbc.Card([\n                dbc.CardBody([dcc.Graph(id='rating',figure={},style={'height': '167px'})\n                            ])\n                 ],className='mb-1 ')\nbarplot=dbc.Card([\n                dbc.CardBody([dcc.Graph(id='bar',figure={},style={'height': '350px'})\n                            ])\n                 ],className='mr-0 ')\n\npiechart=dbc.Card([\n                dbc.CardBody([dcc.Graph(id='pie',figure={},style={'height': '350px'})\n                            ])\n                 ],className='mb-1 ')\ntable=dbc.Card([\n                dbc.CardBody([dcc.Graph(id='table',figure={},style={'height': '350px'})\n                            ])\n                 ],className='mb-1 ')\n\n#piechart=dcc.Graph(id='pie',figure={})\n#barplot=dcc.Graph(id='bar',figure={})\n#table=dcc.Graph(id='table',figure={})\n\n\napp.layout = dbc.Container([dbc.Row( dbc.Col(html.H2(children=' Software Professionals Salary Dashboard  2022',className=\" text-center p-1 border  border-primary border-top-0  p-2\",\n                                                    style = {'color':'white','background-color':'#1C4E80','font-size':'30px'}),width=12)\n    \n                                    ),dbc.Row(),\n                            \n                            \n                            dbc.Row([dbc.Col(html.H5('Select Job Role:',style={'font-size': '40px'}),style={'color':'#1C4E80'},className='mb-2  mt-2',width=2),\n                                dbc.Col(dropdown1 ,className='mb-2  mt-1',width=4),\n                                     dbc.Col(html.H5('Select Location:',style={'font-size': '20px'}),style={'color':'#1C4E80'},className='mb-2  mt-2',width=2),\n                                     dbc.Col(dropdown2,className='mb-2  mt-1',width=4)\n                                     \n                            \n                                    \n                                    ]),\n                            dbc.Row([dbc.Col(histogram,width=8),\n                                     dbc.Col(dbc.Row([average_salary,rating]),width=4)                  \n                                    \n                                    ]),\n                            \n                            dbc.Row([dbc.Col(barplot,width=4),\n                                     dbc.Col(piechart,width=4),\n                                     dbc.Col(table,width=4)\n                                   \n                                    ])\n    \n                           ]\n                     \n\n                           \n\n                           \n                           ,fluid=True,style= {'background-color':'#F1F1F1'})\n########################################### backend callbacks and functions #####################################################\n\n@app.callback(\n    Output('salary', 'figure'),\n    [Input('dropdown1', 'value'),\n    Input('dropdown2','value')]\n     )\n\ndef average_salary(role='All',location='All'):\n    if role!= 'All':\n        temp_df= df[(df['Job Roles']== role) & (df['Salary']< 4000000)]\n        if location != 'All':\n            new_data = temp_df[temp_df['Location']==location]\n           \n            fig=salary_meter(new_data)\n   \n        elif location == \"All\":\n            \n            fig=salary_meter(temp_df)\n        else:\n            \n            fig=salary_meter(temp_df)\n                \n        return fig\n\n    else:\n        if location!= 'All':\n            temp_df= df[(df['Location']== location) & (df['Salary']< 4000000)]\n            fig=salary_meter(temp_df)\n\n\n        else :\n            fig=salary_meter(df)\n        return fig\n############################################# rating component \n@app.callback(\n    Output('rating', 'figure'),\n    [Input('dropdown1', 'value'),\n    Input('dropdown2','value')]\n     )\ndef rating(role=dropdown1,location=dropdown2):\n    if role!= 'All':\n        temp_df= df[(df['Job Roles']== role) & (df['Salary']< 4000000)]\n        if location != 'All':\n            new_data = temp_df[temp_df['Location']==location]\n           \n            fig=meter(new_data)\n   \n        elif location == \"All\":\n            \n            fig=meter(temp_df)\n        else:\n            \n            fig=meter(temp_df)\n                \n        return fig\n\n    else:\n        if location!= 'All':\n            temp_df= df[(df['Location']== location) & (df['Salary']< 4000000)]\n            fig=meter(temp_df)\n\n\n        else :\n            fig=meter(df)\n        return fig\n################################################### salary histogram  component\n@app.callback(\n    Output('hist', 'figure'),\n    [Input('dropdown1', 'value'),\n    Input('dropdown2','value')]\n     )\n\ndef salary_hist(role=dropdown1,location=dropdown2):\n\n    if role!= 'All':\n        temp_df= df[(df['Job Roles']== role) & (df['Salary']< 4000000)]\n        if location != 'All':\n        \n            fig = px.histogram(temp_df[temp_df['Location']==location],x= 'Salary',template='simple_white',\n                              color_discrete_sequence=['#1C4E80'],\n                               nbins = 20,barmode='group')\n            fig.update_layout(title ={'text': \"<b style:'color:blue;'>{0}  Salary at  {1}</b>\".format(role,location), 'font': {'size': 16}},title_x=0.5,\n                        #title_font_family=\"Times New Roman\",\n                               title_font_color=\"slategray\",margin=dict(b=10,r=40), yaxis_title={'text': \"Number of Employees\"}, font_color='slategray')\n                       #,\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                  #  yaxis_title={'text': \"<b style:'color:blue';>Number of Employees </b>\"}\n                           \n                            # plot_bgcolor='rgba(0,0,0,0)'\n                              \n\n        elif location == \"All\":\n            fig = px.histogram( temp_df,x= 'Salary',template='simple_white',nbins = 20,barmode='group', color_discrete_sequence=['#1C4E80'])\n            fig.update_layout(title ={'text': \"<b style:'color:blue;'>{0} Salary </b>\".format(role)\n                                , 'font': {'size': 16}},title_x=0.5,\n                        #title_font_family=\"Times New Roman\",\n                                 title_font_color=\"slategray\",margin=dict(b=10,r=40), yaxis_title={'text': \"Number of Employees\"}, font_color='slategray')\n                       # font_color='blue',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                   # yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n               # paper_bgcolor='white',\n               #         plot_bgcolor='rgba(0,0,0,0)'\n         \n        else:\n            \n            fig = px.histogram( temp_df,x= 'Salary',template='simple_white',nbins = 20,barmode='group',color=location, color_discrete_sequence=['#1C4E80'])\n\n            \n        return fig\n\n    else:\n\n            \n        \n        if location!= 'All':\n            temp_df= df[(df['Location']== location) & (df['Salary']< 4000000)]\n            fig = px.histogram(temp_df,x='Salary',template='simple_white',nbins = 20,barmode='group', color_discrete_sequence=['#1C4E80'])\n            fig.update_layout(autosize=True,title ={'text': \"<b style:'color:blue;'>Salary at {0}</b>\".format(location), 'font': {'size': 16}},\n                              title_x=0.5,title_font_color=\"slategray\",margin=dict(b=10,r=40), yaxis_title={'text': \"Number of Employees\"}, font_color='slategray')\n                        #title_font_family=\"Times New Roman\",\n                              \n                       # font_color='blue',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                   # yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n                    #    paper_bgcolor='lightblue',\n                      #  plot_bgcolor='rgba(0,0,0,0)')\n         \n \n\n        else :\n            fig = px.histogram(df[df['Salary']< 4000000],x='Salary',template='simple_white',nbins = 20, color_discrete_sequence=['#1C4E80'])\n                \n            fig.update_layout(title ={'text': \"<b style:'color:blue;'>Overall Salary at All Locations</b>\"\n                            , 'font': {'size': 16}},title_x=0.5,title_font_color=\"slategray\",margin=dict(b=10,r=40),yaxis_title={'text': \"Number of Employees\"}, font_color='slategray')\n                              \n                        #title_font_family=\"Times New Roman\",\n                        \n                       # font_color='blue',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                   # yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n                        #   paper_bgcolor='white',\n                        #   plot_bgcolor='rgba(0,0,0,0)'\n    \n        return fig\n ######################################  Location bar chart   component \n@app.callback(\n    Output('bar', 'figure'),\n    Input('dropdown1', 'value'),\n\n     )\ndef bar(role:str):\n    if role=='All':\n        temp_df= location_sorting(df)\n        fig= px.bar(temp_df,y= 'Location',x='Count',color='Location',template='simple_white',color_discrete_sequence=px.colors.sequential.Blues_r,\n                orientation='h'\n             )\n        fig.update_traces(showlegend=False)\n        fig.update_layout(margin=dict(b=10,r=10,l=0),\n                        title ={'text': \"<b style:'color:blue;'> Top Locations</b>\", 'font': {'size': 16}},title_x=0.5,\n                        #title_font_family=\"Times New Roman\",\n                        title_font_color=\"slategray\",\n                        font_color='slategray',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                    yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n                    paper_bgcolor='white',\n                    plot_bgcolor='rgba(0,0,0,0)')\n        return fig\n        \n    else:\n        temp_df = df[df['Job Roles']== role]\n    \n        temp_df=location_sorting(temp_df)\n        fig= px.bar(temp_df,y= 'Location',x='Count',color='Location',template='simple_white',color_discrete_sequence=px.colors.sequential.Blues_r,\n                    orientation='h' )\n        fig.update_traces(showlegend=False)\n        fig.update_layout(\n                        title ={'text': \"<b style:'color:blue;'>Top Locations for {0}</b>\".format(role), 'font': {'size': 15}},title_x=0.5,\n                        #title_font_family=\"Times New Roman\",\n                        title_font_color=\"slategray\",margin=dict(b=10,r=10,l=0),\n                        font_color='slategray',\n\n                   # xaxis_title={'text': \"<b style:'color:blue;'>Likes</b>\", 'font': {'size':15}},\n                    yaxis_title={'text': \"<b style:'color:blue';></b>\", 'font': {'size': 15}},\n                    paper_bgcolor='white',\n                    plot_bgcolor='rgba(0,0,0,0)')\n        return fig\n########################################################  Pie chart component \n@app.callback(\n    Output('pie', 'figure'),\n    [Input('dropdown1', 'value'),\n    Input('dropdown2','value')]\n     )\ndef pie(role=dropdown1,location=dropdown2):\n\n    if role!= 'All':\n        temp_df= df[(df['Job Roles']== role) & (df['Salary']< 4000000)]\n        if location != 'All':\n            new_data = temp_df[temp_df['Location']==location]\n            data= new_data['Employment Status'].value_counts()\n            fig=donut(data)\n   \n        elif location == \"All\":\n            data = temp_df['Employment Status'].value_counts()\n            fig=donut(data)\n        else:\n            data = temp_df['Employment Status'].value_counts()\n            fig=donut(data)\n            \n\n            \n        return fig\n\n    else:\n\n            \n        \n        if location!= 'All':\n            temp_df= df[(df['Location']== location) & (df['Salary']< 4000000)]\n            \n            data = temp_df['Employment Status'].value_counts()\n            fig=donut(data)\n\n\n        else :\n           \n            data = df['Employment Status'].value_counts()\n            fig=donut(data)\n        return fig\n############################################################################# table component \n@app.callback(\n    Output('table', 'figure'),\n    [Input('dropdown1', 'value'),\n    Input('dropdown2','value')]\n     )\n\ndef Company_table(role=dropdown1,location=dropdown2):\n    if role!= 'All':\n        temp_df= df[(df['Job Roles']== role) & (df['Salary']< 4000000)]\n        if location != 'All':\n            new_data = temp_df[temp_df['Location']==location]\n           \n            fig=Table(new_data)\n   \n        elif location == \"All\":\n            \n            fig=Table(temp_df)\n        else:\n            \n            fig=Table(temp_df)\n                \n        return fig\n\n    else:\n        if location!= 'All':\n            temp_df= df[(df['Location']== location) & (df['Salary']< 4000000)]\n            fig=Table(temp_df)\n\n\n        else :\n            fig=Table(df)\n        return fig    \n###############################################################################################   \nif __name__ == '__main__':\n    app.run_server(mode='inline',port=8050)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-17T13:26:32.496979Z","iopub.execute_input":"2022-07-17T13:26:32.497524Z","iopub.status.idle":"2022-07-17T13:26:32.643603Z","shell.execute_reply.started":"2022-07-17T13:26:32.497475Z","shell.execute_reply":"2022-07-17T13:26:32.642441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# dashboard link    http://rushikesh20.pythonanywhere.com/","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}