Building Python-based, database-driven web applications (with maps!) using Flask, SQLite, SQLAlchemy and MapBox
2019-06-17
1 Preface
1.1 Our goal
All right, crew, we’re going to build a web application, which is a fancy way of saying “web site that talks to a database.” Except that isn’t necessarily true, as it might also just mean “a fancy web site.” But we’re pretending it’s approximately 2012 and that’s still what a web application mostly is, because the world’s too confusing as it is.
1.2 Every step we’ll take
Our steps are going to look something like this:
- Set up a little website that doesn’t do much at all
- Take some data from a CSV and put it into a little database
- Connect our little website to our little database
- Make the website reflect what’s in the database (so if you update the database, you update the website!)
- Add some cool maps to our website so people know we mean business
- Add all other sorts of miscellaneous bells and whistles to our website, too(t toot)**
** That’s a solid joke about a whistle
1.3 Why in the name of undiscovered species am I doing this?
Usually when you get a big ol’ set of data you need to analyze it. Take various types of averages, look at distributions, stuff like that. Sometimes, though, it’s more important to browse.
For example: It’s nice to know that in theory some surgeons are good and some surgeons are bad, but it’s more useful to know which surgeons are good and which surgeons are bad. And thanks to ProPublica’s Surgeon Scorecard, we can do a little searching and figure out exactly how the landscape looks!
Typically you end up with an automatically-generated web page for every single item in your database - whether it’s a doctor, or a school, or a company. That page can list all of the sorts of data that’s hiding in your database about that doctor, school, or company… but in a nice friendly that’s palatable to people who are allergic to Excel et al.
And with charts, even!!! Or maps!!!
You aren’t restricted to showing that single item, either - you should show related schools, compare the selected doctor to others others nearby, or contextualize a company’s earnings based on the earnings of all other companies in your database. Any comparative analysis you could do piece-by-piece you can code to display automatically on your web page!