Build global terrorism database dashboard in python by plotly dash with two input components drop down list and range slider using plotly interactive data visualization library and dash web app library.
Inputs: Two dependent drop down lists with (chained callbacks) and range slider.
Though this dashboard has same data set as well as previous version of dashboard. But this global terrorism database dashboard in python by plotly dash is fully dynamic and it has three input components. Two drop down lists and range slider. Using these three components, it is easy to analyze data on this dashboard. We can select any region and country name from the drop down list and specific period for that region and country to track specific data. Scattermapbox map chart is connected to drop down list and range slider is also connected to scattermapbox. Selecting any input value reflects on scattermapbox. In this way, we can see data on scattermapbox for specific period. You need to create free account on Mapbox website to use it because scattermapbox need token to display data on each country geographic location. Use below link to create free Mapbox account. How to use scattermapbox map chart in plotly dash? Download full code, if you have any problem to learn this code, comment in the comment box, I will help you as soon as possible.
The second chart is the combination of line and stack bar chart. Two input components are connected to this chart. This chart is fully dynamic and changed according to selected values from the input components. The benefit of this chart is that we can select specific period using range slider and we can get values over the selected period. To create stack bar chart in this chart, don’t forget to enter bar mode parameter is equal to stack in the layout of this chart. As a result, you will have stack bar chart. Change the background color of this chart as well as background color of app. You can see more in the code for more details. Pie chart is the third chart and it is also connected two input components of dash. Selecting any value from the drop down list and range slider, pie chart is automatically updated. Create specific data frame for this chart using the main data frame. It shows three types of data that are total deaths, total wounded and total attack. These values are changed dynamically for selected country by changing in the drop down list. You can see more details using the below link in the code for pie chart.
Important: There are 135 columns in the original data set. You need to download original data set using the below link, then select only 10 columns and create new csv files using pandas function. The list of columns you can see below that I have used in this dashboard. [‘region_txt’, ‘country_txt’, ‘provstate’, ‘city’, ‘iyear’, ‘latitude’, ‘longitude’, ‘nkill’, ‘nwound’, ‘attacktype1’]
See below how this dashboard work?
I have created this dashboard using two CSS files to make it responsive on any device. The below file can be downloaded from the plotly website dash docs page. This CSS file is special created for dash web apps to make charts responsive and resizeable on any device.
I have created below CSS file to adjust the position of grids on the webpage. Use also below code in your code editor in the assets folder by creating .css extension file.
Create free Mapbox account using below link to use token in the scattermapbox map chart.
Download the full code and CSV data file and learn more about plotly dash on Udemy.