How to Build a Map Dashboard with Python ASAP | by Christos Zeglis | Towards Data Science

We have already seen how easy it is to plot some data on a map using python along with the geoviews library. However, truth be told, it can get quite frustrating editing lines of code each time you want to change specific aspects of what’s displayed on the plot. For this reason, it is often more useful and convenient to build a map dashboard where changes on the plot can be done within few clicks even by the most inexperienced user. Luckily enough, there is an easy way to make this happen, using Panel and Param.
Panel is an open-source Python library that lets you create custom interactive web apps and dashboards by connecting user-defined widgets to plots, images, tables, or text. Panel can also be used with the separate Param project to create interactively configurable objects with or without associated visualizations, in a fully declarative way.
For the purposes of this tutorial, we are going to build a map dashboard to visualize the passengers volume for the busiest airports in my country, Greece, and the neighbor country, Turkey, for comparison reasons, just as we did in the demonstration of the geoviews.Points module. This time the dataset is updated with the passenger volumes of the year 2019, now containing both the 2018 and the 2019 figures, as well as the new airport in Istanbul.
The dataset can be found here.
First, we need to import the neccessary libraries and modules we are about to use.
import pandas as pdimport numpy as npimport geoviews as gvfrom geoviews import opts, dim import param, panel as pngv.extension('bokeh')
We read the aforementioned dataset as airports_df which looks like this.
Now let’s do some prep work.
We create the HoverTool to specify the information displayed when we hover over the points.
from bokeh.models import HoverTooltooltips = [('IATA', '@IATA'),            ('Passengers', '@passengers{0.000 a}m'),            ('City', '@city'),            ('Country', '@country'),            ('Longitude', '$x'),            ('Latitude', '$y'),            ('Year', '@year')            ]hover = HoverTool(tooltips=tooltips) 
We create a list which contains all the countries and also the value “All”. So in this case it contains the values [‘GR’, ‘TR’, ‘All’]. We will use that list on our dashboard parameter ‘Country’.
country_list = airports_df['country'].unique().tolist() country_list.append('All')country_list
We also create a dictionary that contains the main options for the tilemap we use and therefore for the whole plot.
topts = dict(width=1100, height=680, xaxis=None, yaxis=None, \    show_grid=False)
Now let’s build the dashboard using Param and Panel. The structure is as follows. First, we define the main object using Param, where we set the parameters of the dashboard options. Inside the Param object, we also define the plot, where we pass the parameters set by the user.
Now, all we have to do is pass the above object to dashboard and use Panel to display the dashboard.param and dashboard.plot in a row i.e. parameters on the left, plot on the right.
dashboard = Airports(name="Airports Dashboard")DashboardPanel = pn.Row(dashboard.param, dashboard.plot)
Lastly, there are two ways to run the dashboard. Either within the same jupyter notebook or in a separate tab.
For the first option simply type
DashboardPanel.servable()
While for the second option simply type
DashboardPanel.show()
The dashboard will look like this.
Of course, one can add many more parameters and plots on their dashboard. This one was made just for demonstration purposes.
That’s it for today. Hope you found it useful. Till next time!
You can always find me on LinkedIn by clicking here.