Incorporating the Functionality into the App
Learn how to add bar charts and drop-down components to a Dash application.
We'll cover the following...
We are now ready to add the new functionality to our app again using the function and chart we just created. At this stage, not much explanation is required since we’ve done this enough times. But we’ll go through the main steps, and we can always refer to the code repository to check our work.
-
Lines 1–15: At the top of the module, we first make the DataFrame definitions as well as column changes, like we did before. Make sure that the code is placed after creating the
povertyDataFrame because the code depends on the DataFrame. -
Lines 17–20: For the layout part, we add an
h2element as a title for the new section, aDropdowncomponent for countries, and aGraphcomponent right under the last charts we created for the Gini index section. -
Lines 22–39: We construct the
callbackusing the code we just worked with.
Adding this code in the right places should add the new functionality to our app. We now have multiple indicators that our users can interact with, and several of them provide different ways of looking at the data.
The four ways to display bar charts can be interesting, but in our case, if we want to allow users to compare more than one country, it would quickly become almost impossible to read. Going back to our Gini index country chart, for example, each selected country typically displays 20 ...