...
/Incorporating the Function into the App
Incorporating the Function into the App
Learn how to add a stand-alone function to a Dash application.
Final goal
Here’s the plan for the functionality that we are going to introduce:
- Create a drop-down list using the countries and regions available in our dataset.
- Create a callback function that takes the selected country, filters the dataset, and finds the population of that country in the year 2010.
- Return a small report about the found data. The illustration below shows the desired end result:
The illustration below shows what this folder structure might look like:
We’ll run a minimal app in JupyterLab, make sure it is running properly, keep a copy, and then add it to the app.
We first need to take a look at the dataset, explore it a little bit, and learn how to implement the new functionality.
Visualizing our DataFrame
To view what files we have in the dataset, we can run the following code:
import osprint(os.listdir('../data'))
For now, we’ll be working with the PovStatsData.csv
file. For a quick overview of its structure, we can run the following:
import pandas as pdpoverty_data = pd.read_csv('../data/PovStatsData.csv')print(poverty_data.head(3))
It seems that we have two fixed variable columns (“Country Name” and “Indicator Name”). Measured variables in the form of numeric data (or missing NaN) values are available under their respective year column. Here, the years span from 1974 to 2019 (note that not all of the years are shown for better readability). The countries and indicators also have codes, which can be useful later when we want to merge different DataFrames.
Note: ...