TDM 40200: Project 8 — 2023
Motivation: Dashboards are everywhere — many of our corporate partners' projects are to build dashboards (or dashboard variants)! Dashboards are used to interactively visualize some set of data. Dashboards can be used to display, add, remove, filter, or complete some customized operation to data. Ultimately, a dashboard is really a website focused on displaying data. Dashboards are so popular, there are entire frameworks designed around making them with less effort, faster. Two of the more popular examples of such frameworks are shiny
(in R) and dash
(in Python). While these tools are incredibly useful, it can be very beneficial to take a step back and build a dashboard (or website) from scratch (we are going to utilize many powerfuly packages and tools that make this far from "scratch", but it will still be more from scratch than those dashboard frameworks).
Context: This is the seventh in a series of projects focused around slowly building a dashboard. Students will have the opportunity to: create a backend (API) using fastapi
, connect the backend to a database using aiosql
, use the jinja2
templating engine to create a frontend, use htmx
to add "reactivity" to the frontend, create and use forms to insert data into the database, containerize the application so it can be deployed anywhere, and deploy the application to a cloud provider. Each week the project will build on the previous week, however, each week will be self-contained. This means that you can complete the project in any order, and if you miss a week, you can still complete the following project using the provided starting point.
Scope: Python, dashboards
Dataset(s)
The following questions will use the following dataset(s):
-
/anvil/projects/tdm/data/movies_and_tv/imdb.db
Questions
Interested in being a TA? Please apply: purdue.ca1.qualtrics.com/jfe/form/SV_08IIpwh19umLvbE |
Question 1
This project assumes you have a working backend and frontend from the previous project. Need a clean slate? You can copy over a working API starting Saturday, March 4th.
Then, to run the API, first load up our Python environment.
Next, find an unused port to run the API on.
Then, run the API using the port from the previous step, in our case, 7777.
In addition, open another terminal to run the frontend using another port, in our case, 8888.
You can visit the following links to see the barebones pages. |
The goal of this project is to create functioning forms that allow a user to add a new person and title to the database. We will break down the steps for you, as forms can be a bit confusing.
Let’s start by creating templates for our 2 new forms: create_person.html
and create_title.html
. These are templates that will live in our frontend. Use the following resource to put together the <form>
elements for each of these pages.
Pay close attention to the |
You can use this as a starting point for your templates.
|
Don’t forget your "submit" button! This will be responsible for making the request to the given endpoint in your |
For this project, our people request will have the following fields: |
-
Code used to solve this problem.
-
Output from running the code.
Question 2
Next, its time to create endpoints that will show our forms! Since these endpoints will only be responsible for displaying our form, they should be part of our frontend. We will create 2 endpoints:
-
GET /people/create
-
GET /titles/create
These endpoints should simply display the forms we created in the previous step.
For this question, include a screenshot showing each of your forms in the browser.
-
Code used to solve this problem.
-
Output from running the code.
Question 3
At this stage, you should be able to pop open a browser and visit localhost:8888/people/create/
and localhost:8888/titles/create/
and see your forms. However, if you try to submit the form, nothing will happen — after all, we haven’t created the api endpoints that will handle the form submissions yet!
Let’s start that process now.
First, create two new queries in your queries.sql
file: create_person
and create_title
. These queries should insert a new row into the people
and titles
tables, respectively.
For this question, paste the queries (the complete additions to the queries.sql
file) in a jupyter notebook markdown cell.
-
Code used to solve this problem.
-
Output from running the code.
Question 4
Finally, create two new api endpoints (in your backend). These endpoints should be straightforward and do the following.
-
Establish a connection to the database.
-
Insert the data.
-
Return a
dict
with values as a form of a success message.
If you want a field to be optional, you’ll want to do something like:
|
These will need to be |
For this question, go ahead and test it out! Please use your new forms to create a new person and new title. Include screenshots of the forms right before clicking "submit". Then, include screenshots of the forms right after clicking "submit".
-
Code used to solve this problem.
-
Output from running the code.
Question 5
Last but certainly not least, lets go ahead and view our new title and person using our frontend. Navigate to the following pages and include screenshots of the pages in your notebook.
-
Code used to solve this problem.
-
Output from running the code.
Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted. In addition, please review our submission guidelines before submitting your project. |