Mapping Military Biographies - Part 1

Introduction

I’m a big fan of military biographies and I’ve always been fascinated by maps, so I decided to develop a web application to help me map the locations that are mentioned in these books. I’ve been using R and Shiny for some years at this point, so it was a natural choice to develop a mapping application using these tools.

Shiny is an R package that provides a framework for building and deploying interactive web applications. Just like a standard website, Shiny apps can be supplemented with CSS and JavaScript, but generally the built-in widgets and features are sufficient. I tend to think of the Shiny service as a web server with a statistical and visualisation back-end provided by R. Shiny applications can be deployed using Shinyapps.io or alternatively via your own Shiny server. The first option is a cloud-based service and is a useful place for beginners to start. Hosting your own Shiny server is a more advanced option and requires a Linux server, but more on this later.

Application Components

There are two main components to this application:

  1. Data entry for inputting and storing the data

  2. Data visualisation for displaying and exploring the data

The data for the application could potentially be captured in Excel and stored in a spreadsheet or text file, but then that wouldn’t make a very interesting data science project! Better yet, the data could be stored in a relational database but this requires a database server of some kind and a bit of heavy-lifting to set up the database schema. A simpler option which I ended up using is to store the data in a number of .rds files, which are files that store R data objects. These can be used to mimic a database structure, where each file contains data from one relational table. I also didn’t have my own Shiny server when I began developing the application, so this was another reason for avoiding a database. This article gives some useful additional background on data storage with Shiny.

The data visualisation and mapping are done using R and Shiny in conjunction with Leaflet, which is a ‘JavaScript library for … interactive maps’. I have used Leaflet to produce a number of applications in my regular employment, and the maps it produces are superb. The R implementation of Leaflet has built-in functions that help integrate it with Shiny, and the documentation is generally helpful. One of the things I really like about Leaflet is the support for map tiles by third parties which you can browse here.

Data Entry with Shiny

If you are planning on using Shiny to produce a web form for data entry, I highly recommend this blogpost by Dean Attali. I leaned heavily on his methodology and his blog has a lot of other great material for improving your Shiny applications. The general idea is to develop a Shiny application to mimic a form, using the input widgets in conjunction with some functions to create, read, update and delete records (CRUD).

Its always advisable to sketch out the requirements for a new application, particularly if you are developing it for other stakeholders. The disadvantage of working on your own projects is that the planning phase can feel unnecessary, leading to a lot of heart-burn later on. Initially, I only had a vague idea of what I was hoping to produce, so the end-result emerged pretty organically.

The first thing I needed to decide was which data to capture. If I want to produce a map, all I need is a latitude and longitude with a unique ID, right? Maybe not. In addition to this, each coordinate has a date, a country and - looking forward to a time when I have a lot of data - a theatre of operation (Western, Eastern, Pacific etc.). I also needed to tie the coordinate back to the biography, which is written by an author who may or may not be the actual person who fought in the war. So I figured that in addition to the positional data, I would need to keep a record of the book, the author and the subject of the book.

With respect to the combatant, I recorded their nationality, service branch (army, air force etc.), military specialty (gunner, driver, rifleman etc.) and military rank. Finally, I gave each coordinate an event category, which grew steadily each time I read another biography. The idea behind the event category was to tag each location according to what was happening to the combatant at that specific point in time and space. Typical events were very high-level and included: front-line; reserve; leave; wound; convalescence and so on.

Application Layout

In the end, I settled on a Shiny application with multiple tabs for all the various components (see following screenshots).

  1. Book - a web form for capturing the details of the book. Fields include the book title, author and ISBN. In addition to the input elements the page has a table of book entries and a cover photo.

Figure 1. View of application Book tab

  1. Combatant - a web form for capturing the details of the combatant. Fields include name, DOB, nationality, service and book title. The page also has a table of all the combatant entries and a photo.

Figure 2. View of application Combatant tab

  1. Place - a web form for capturing the details of the map locations. Fields specify the combatant ID, operational theatre, unit, rank, date, country, coordinate and notable event. Also includes a table of the place entries, and a map for finding coordinates.

Figure 3. View of application Place tab

  1. Map - an interactive map for browsing the location data captured in the preceding forms. There are filters for date, operational theatre, book and notable event.

Figure 4. View of application Map tab

The last tab is effectively the end result of the process and is the basis of a stand-alone Shiny application which you can see at shinyapps.io and immediately hereafter.

In the next post, I’ll get into some of the details about how each of these components were coded.

Related