In this post, let’s go over the creation of web application to capture user behavior. Docker and compose are required if you want to simulate the work.
Our app will soon take shape as showed below. So, let’s get started.
Web-Client
Save this into a file named angular.Dockerfile and run,
We have mounted the current directory as /usr/local/bin/imdb-app in our docker container so as to persist our work.
Let’s generate our app scaffolding with,
Now, run the application using,
In your web browser, visiting http://localhost:4200 should show a Hello, World! message.
We will be editing the files in <your current directory/imdb-app/angular below. You should see this webpage refresh automagically as you make edits to these files.
Let’s get to work to add a form so that user can enter movie and/or actor on the webpage. We’ll edit the app.component.(html/ts) files. Once we are done, the page will look as showed below.
We are going to use Angular Material to style our webpage, so let’s go ahead and install it first. Inside the docker container run,
Add the following Material modules to src/app/app.module.ts file.
Add the following code to app.component.ts and app.component.html files, respectively.
Disclaimer: You should be using Form Controls, Form Groups and Form Validations for a production app. We are only covering the bare essentials to get the big picture going.
Okay, so with that we’ve got our UI all set so as to gather input parameters required to fetch the actor/movie information from IMDB dataset we have downloaded as explained in this post.
Now, it’s time to bring our server side application to life and serve IMDB actor/movie information based on user input.
Web-Server
Save this into a file named flask.Dockerfile and run,
Pointing your web browser to http://localhost:8080/, you should see Hello, World! message.
It’s time to grab the imdb_process.py and place it in imdb-app/flask/modules/ folder. We will use this module in the API end point we are going to add to our server.py below.
Also, move actors.tsv and movies.tsv imdb datasets to imdb-app/flask/assets/imdb_data/ folder.
Now, our web-server is ready to serve the movies’ information of the actors requested.
Web-Client
Let’s test this new feature using our web-client application. But first, we need to add some code to UI.
Import HttpClientModule in our app.module.ts file.
Create movie.service.ts file in src/app/services/ folder and add the code below.
Now, let’s make use of movie.service.ts in app.component.ts.
Finally, let’s add a bit of code to app.component.html and app.component.scss files, respectively.
Recompile the Angular app (just in case, if you are having any issues), using,
Just like that, we have a fully working web-application that serves the movies for the actors provided in the web-form.