WHO statistics data dashboard in python by plotly dash

WHO statistics data dashboard in python by plotly dash
WHO statistics data dashboard in python by plotly dash

Create WHO statistics data dashboard in python by plotly dash using plotly interactive data visualization library and dash web app library.

There are three charts in this WHO statistics data dashboard in python by plotly dash. Two charts are dynamically changed and one chart is static. Choropleth static map chart is not connected to drop down list and it shows data for each country on the chart. This view can be seen by hovering on the chart each country geographic location. Line chart displays data for each country over the specific period. This chart is connected to the drop down list and selecting any country name from the list it shows data for that selected country. Similarly horizontal bar chart displays data for top age group for selected country.

Import Library

Lines 1-6

Start creating this dashboard by importing necessary library. Make sure you have installed this library in your machine or code editor. I recommend you PyCharm editor to run dash apps in this code editor. I have used dash library, dash html components, dash core components, plotly interactive graph objects data visualization library and pandas for data analysis and manipulating data for creating this dashboard.

Data

Line 10

Download the CSV data file using the below link above the code template. Use pandas read function to read this file. Give the name this data frame as you want because this data frame will be used below in the code during the development of dashboard.

Title

Lines 13-28

Let’s start to create this dashboard. Follow the code below in the code template and copy the code and paste in your code editor. First of all create layout of dash app. Inside the layout of dash app give the name of this dashboard and also give author name of this dashboard right side of the title. Style these two names using html style properties and place these two names according to your system screen resolution.

Drop Down List

Lines 32-52

Next I create input component for this dashboard using dash core components library of dash. I have inserted only one input component that is drop down list. Before I have created layout of choropleth map chart. This map chart is static chart and it is not connected to the drop down list. Use name of data frame and name of column in options parameter to get unique country name list in the drop down list.

Charts

Lines 55-73

Create the layout of remaining two charts. Give unique id to these two charts. Adjust the position of these two charts according to your system screen resolution using html style properties. I have not used dash bootstrap components in this dashboard. Dash bootstrap components automatically adjust the layout of app in any screen resolution device.

Data and Layout for each chart

Lines 108-667

First I create data frame for Choropleth map chart. You can view that data frame below in the code template line 79. In data section of this chart, you can see in line 84 I have used locations parameter to display geographic location of each country on the map chart from to the country column of data frame. z parameter is used in Choropleth map chart to display data on each geographic location of country on the map chart. Use color scale to show unique country location by color and create hover effect for each country location.

Line chart is second chart in this dashboard. You can see in the above image, there are six lines. Each line represents data for age group and by selecting any country name from the list, data is changed on the line chart according to the selected country over the period. x-axis of this chart shows year values and y-axis shows no. of suicides for selected country. Mode parameter is used in line chart to display line on the line chart. We can also add markers property in the mode parameter to display markers on the line.

Third chart is Horizontal bar chart. This horizontal bar chart displays values for top age group for the selected country in the drop down list. Create new data frame for this chart. You can view this data frame in the code template lines 305 to 306. You can see in the above image, each horizontal bar displays data. I have created text template for this. Select text position auto because text will automatically adjusted inside the bars or outside the bars. It depends on the length of bars. You can view more details below in the code template lines 312 to 314.

Download the csv data file using the below link.

https://www.kaggle.com/szamil/who-suicide-statistics

To see full code,hover on the code area and use horizontal scrollbar if needed.


If you have any problem in learning above code, please comment in the comment box. I will help you as soon as possible.


Recommended For You

About the Author: Mubeen Ali

I am passionate about learning Dash. Dash is a python framework that creates beautiful web based data visualization dashboards.