Properties of Dash's Callback Functions

Let’s recap the properties of Dash’s callback function and introduce a few others that will be explored in more detail later on.

Multiple inputs

As mentioned, we can give callbacks to more than one input and create more complex functionality. Using our dataset as an example, we can easily imagine a drop-down to select countries, another to select dates, and yet another to specify the economic indicator that we want to analyze. Those inputs could be used to filter a subset of the DataFrame and return the values that we want, based on multiple criteria.

Inputs can be lists

Here we refer effectively to multiple values from a single Input. The country selector can be made to accept multiple values, so we can loop over them and visualize the same trend for the same indicator for multiple countries in one chart (or a chart per country).

Multiple outputs

As with multiple inputs, multiple outputs can be modified using one callback function. In our example, we might imagine producing two outputs—one that is a chart visualizing the filtered data and another that is a table—providing the user with the raw data if they want to export and further analyze this particular subset.

Functions do other things before returning

We have mainly focused on callbacks being simple processors of data, but they can really do anything before returning. For example, we can imagine a function sending an email under certain conditions.

Logging is another interesting thing to explore. All we have to do is simply log the arguments given to each function. This can give us insights into what people are interested in, which functionality is being used, and more. We can even parse those logs and develop our own separate analytics app based on that!

Order matters

Outputs have to come before inputs. Additionally, the order of inputs corresponds to the parameters and their order of the callback function. For example, take a look at the following:

Get hands-on with 1200+ tech skills courses.