Final Project Part 2 Dashboard
Final Project Part 2 Dashboard
Table of content
Scenario
Components of the report items
Dataset Variables
Requirements to create the dashboard
Review and Task
Tasks to be performed
Once you close your session or it is timed out due to inactivity, you are logged off, and this ‘dedicated computer on the cloud’ is deleted along with any files you may have
created, dowloaded or installed. The next time you launch this lab, a new environment is created for you.
If you finish only part of the lab and return later, you may have to start from the beginning. So, it is a good idea to plan to your time accordingly and finish your labs in a
single session.
Scenario:
The objective of this part of the Final Assignment is to analyze the historical trends in automobile sales during recession periods, as you did in the previous part. The goal
is to provide insights into how the sales of XYZAutomotives, a company specializing in automotive sales, were affected during times of recession.
In this final assignment, you will have the opportunity to demonstrate the Dashboarding skills you have acquired in this course.
This lab aims to assess your abilities in creating various visualizations using Plotly and Dash. As a data scientist, you have been given a task to prepare a report on your
finding from Automobile Sales data analysis.
You decided to develop a dashboard representing two main reports:-
Yearly Average Automobile sales using line chart for the whole period.
For the chosen year provide,
Total Monthly Automobile sales using line chart.
Average Monthly Automobile sales of each vehicle type using bar chart.
Total Advertisement Expenditure for each vehicle using pie chart
Average Automobile sales using line chart for the Recession Period using line chart.
Average number of vehicles sold by vehicle type using bar chart
Total expenditure share by vehicle type during recession usssing pie chart
Effect of unemployment rate on vehicle type and sales using bar chart
NOTE: You have worked creating a dashboard components in Flight Delay Time Statistics Dashboard section. You will be working on the similar lines for
this Dashboard
Dataset Variables:
Dataset Variables for your reference
about:blank 1/6
12/16/23, 5:33 PM about:blank
Each dropdown will be designed in a division
The second dropdown (for selecting the year) should be enabled only if when the user selects “Yearly Statistics report” from the previous dropdown,
else it should be disabled only. - The second dropdown (for selecting the year) should be enabled only if when the user selects “Yearly Statistics report”
from the previous dropdown, else it should be disabled only.
NOTE:- For every task, you will required to save the screenshort/image, which you will be asked to submit for evaluation at the Final Submission stage.
1. 1
1. wget https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMSkillsNetwork-DV0101EN-Coursera/labs/v4/Final_Project/DV0101E
Copied!
You can use this as a base code to complete this final assignment part 2
TASKS
Search/Look for TASK word in the script to identify places where you need to complete the code.
about:blank 2/6
12/16/23, 5:33 PM about:blank
font size as 24
REVIEW link
NOTE: Once the application is up and running, take the screenshort representing the title of the application and save it as ‘Title.png’
TASK 2.2: Add drop-down menus to your dashboard with appropriate titles
and options
Create FIRST dropdown menu and add two Report options to it.
Below is the skeleton:
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
1. dcc.Dropdown(id='....',
2. options=[
3. {'label': '....', 'value': '...'},
4. {'label': '....', 'value': '...'}
5. ],
6. placeholder='....',
7. style={....})
Copied!
Set id as 'dropdown-statistics'.
Set options to list containing dictionaries with key as label and user provided value for labels in value.
1st option
2nd option
OPTIONAL: Set width as 80%, padding as 3px, font size as 20px, text-align-last as center inside style parameter dictionary.
1. dcc.Dropdown(id='....',
2. options=[{'label': i, 'value': i} for i in year_list],
3. placeholder='....',
4. style={....})
Copied!
REVIEW link
NOTE: Take the screenshot representing the two dropdowns with appropriate titles and options and save it as‘Dropdown.png’
TASK 2.3: Add a division for output display with appropriate id and classname
property
Add an inner division to display the output
1. 1
2. 2
3. 3
1. html.Div([
2. html.Div(id='........', className='.........., style={'display': 'flex'}),
3. ])
Copied!
Set id to output-container
className to chart-grid
style it to be displayed as a flex
For reference, observe how code under REVIEW3 has been structured.
We will pass the plots as returned by the callback function into this output-container later refering to the class name of it.
NOTE: Take the screenshort representing the code snippet wherein you have created the output division and save it as ‘Outputdiv.png’
about:blank 3/6
12/16/23, 5:33 PM about:blank
TASK 2.4: Creating Callbacks; Define the callback function to update the input
container based on the selected statistics and the output container
We need two callbacks:-
1. To enable or disable the input container based on the selected statistics.The selected statistics here can be either Recession Statistics or Yearly Statistics.
2. To plot the output graphs for the respective report types.
Once the choice is made by the user, if it is yearly statistics, the input container shall get enabled else it will be in disabled state
and then we can make use of the if-else statement to return appropriate value to the component-property disabled. Refer to the below code snippet:
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
1. @app.callback(
2. Output(component_id='....', component_property='disabled'),
3. Input(component_id='....',component_property='....'))
4.
5. def update_input_container(.....):
6. if ..... =='Yearly Statistics':
7. return False
8. else:
9. return True
Copied!
Our layout has 1 output container, and we will be required to return the plots developed dcc.Graph() into this container as divisions.
For each report we need to display four plots.
we will make use of returning division to the outer-container styled as flex for 2x2 display.
For this callback, there will be two input components : select-year and dropdown-statistics
While the output should be displayed in the output-container, as we opt to display the graphs with divisions using dcc.Graph(), we will make use of children property
here
1. 1
2. 2
3. 3
1. @app.callback(
2. Output(component_id='....', component_property='children'),
3. [Input(component_id='....', component_property='...'), Input(component_id='....', component_property='...')])
Copied!
You need to create seperate dataframe from the dataset according to the report type.
If the selected report is 'Recession Period Statistics', you can fetch the data by using conditions like below:-
1. 1
2. 2
3. 3
4. 4
5. 5
Copied!
On the same lines, you can create the dataframe, according to the year value entered by the user for 'Yearly Statistics report'
NOTE: Take the screenshort representing the the code snippet wherein you have created the two callback functions and save it as ‘Callbacks.png’
TASK 2.5: Create and display graphs for Recession Report Statistics
You will be required to prepare the data as per the plot requirement (usually using groupby())
about:blank 4/6
12/16/23, 5:33 PM about:blank
27. 27
28. 28
29. 29
30. 30
31. 31
32. 32
1. #Plot 1 Automobile sales fluctuate over Recession Period (year wise) using line chart
2. # grouping data for plotting
3. yearly_rec=recession_data.groupby('Year')['Automobile_Sales'].mean().reset_index()
4. # Plotting the line graph
5. R_chart1 = dcc.Graph(
6. figure=px.line(yearly_rec,
7. x='........',
8. y='........',
9. title="........"))
10. ..........
11. #Plot 2 Calculate the average number of vehicles sold by vehicle type and represent as a Bar chart
12.
13. ............
14. # Plot 3 : Pie chart for total expenditure share by vehicle type during recessions
15. # grouping data for plotting
16. exp_rec= recession_data.groupby(...............)
17. R_chart3 = dcc.Graph(
18. figure=px.pie(.............,
19. values='............',
20. names='..........',
21. title="............"
22. )
23. )
24. ..........
25. # Plot 4 Develop a Bar chart for the effect of unemployment rate on vehicle type and sales
26. ............
27.
28. return [
29. html.Div(className='chart-item', children=[html.Div(children=......),html.Div(children=......)]),
30. html.Div(className='chart-item', children=[html.Div(children=......),html.Div(children=......)])
31. ]
32.
Copied!
REVIEW:-
Line Chart
Bar Chart
Pie Chart
NOTE: Once the application is up and running, take the screenshots representing the graphs for Recession report type , [each graph should be clearly captured] and save it
as ‘RecessionReportgraphs.png’
TASK 2.6: Create and display graphs for Yearly Report Statistics
Refer to the code snippet below:-
1. 1
2. 2
3. 3
4. 4
5. 5
6. 6
7. 7
8. 8
9. 9
10. 10
11. 11
12. 12
13. 13
14. 14
15. 15
16. 16
17. 17
18. 18
19. 19
20. 20
21. 21
22. 22
23. 23
24. 24
25. 25
26. 26
27. 27
28. 28
29. 29
30. 30
31. 31
1.
2. # Yearly Statistic Report Plots
3. elif (input_year and selected_statistics=='...............') :
4. yearly_data = data[data['Year'] == ......]
5.
6. ..........
7. # Plot 1 :Yearly Automobile sales using line chart for the whole period.
8. ............
9. yas= data.groupby('Year')['Automobile_Sales'].mean().reset_index()
10. Y_chart1 = dcc.Graph(figure=px.line(.................))
11.
12. ..........
13. # Plot 2 :Total Monthly Automobile sales using line chart.
14.
15. ............
16.
17. ..........
18. # Plot bar chart for average number of vehicles sold during the given year
19. ............
20.
21. avr_vdata=yearly_data.groupby........................
22. Y_chart3 = dcc.Graph( figure.................,title='Average Vehicles Sold by Vehicle Type in the year {}'.format(input_year)))
23.
24. ..........
25. # Plot 4 Total Advertisement Expenditure for each vehicle using pie chart
26.
27. return [
28.
29. html.Div(className='chart-item', children=[html.Div(children=......),html.Div(children=......)],style={'display': 'flex'}),
30. html.Div(className='chart-item', children=[html.Div(children=......),html.Div(children=......)],style={'display': '....'})
31. ]
about:blank 5/6
12/16/23, 5:33 PM about:blank
Copied!
NOTE: Once the application is up and running, take the screenshorts representing all four graphs for the Yearly report types and save it as‘YearlyReportgraphs.png’
Copied!
1. 1
Copied!
1. 1
Copied!
1. 1
1. python3.8 DV0101EN-Final_Assign_Part_2_Questions.py
Copied!
Click on the Launch Application option from the side menu bar. Provide the port number and click OK
Author
Dr. Pooja
Changelog
Date Version Changed by Change Description
2023-08-07 1.2 Lakshmi Holla Updated Instructions
2023-08-03 1.1 Dr. Pooja Included comments in code snippet
2023-06-22 1.0 Dr. Pooja Initial Lab Creation
about:blank 6/6