Deploy your data app on Heroku! | Eric Ma | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Deploy your data app on Heroku!

teacher avatar Eric Ma

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

9 Lessons (27m)
    • 1. Lesson 1: Introduction

      1:04
    • 2. Lesson 2: Prerequisites

      2:02
    • 3. Lesson 3: Create Repository

      2:04
    • 4. Lesson 4: Create Development Environment

      3:20
    • 5. Lesson 5: Create App

      2:52
    • 6. Lesson 6: Configure Heroku

      2:59
    • 7. Lesson 7: Deploy App to Heroku

      8:32
    • 8. Lesson 8: Concepts Review

      3:25
    • 9. Lesson 9: Class Project

      1:01
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

51

Students

--

Projects

About This Class

You're a data scientist, and have made an app prototype. Now, you need to deploy it, so that it's not just simply running on your local machine. Are you stuck on how to do this? Fret not, by the end of this course, you'll know exactly what to do.

Using a simple Streamlit app as an example, by the end of this class, you will know how to configure the app runtime environment, connect Heroku and GitHub together and enable automatic deploys.

Because the focus of this course is on setting up the app deployment workflow, the following topics are not covered in this class:

  • Building a continuous integration pipeline for your project: this is important, but is covered in another class.
  • Versioning machine learning models for deployment.
  • Pulling models from a blob store for prediction.

As this is my first course on Skillshare, please let me know what you think would be a great addition to the class! If you've taken the course and would like to connect, my personal website https://ericmjl.github.io/, and I can be reached at http://shortmail.ericmjl.com/ (which is also a Streamlit app!)

Learn more data science skills at https://www.skillshare.com/browse/data-science.

Meet Your Teacher

Teacher Profile Image

Eric Ma

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Lesson 1: Introduction: Hi there. I'm Eric, and I'm a data scientist who's learned many things about programming, an APP development the hard way. And it's my goal on skill share to make things easier for you by sharing that knowledge in this course, we're going to show you how you can set up automatic deployment of data application prototypes that you've built leveraging her Roku. Now, along the way, I'm going to show you some good practices for developing your app that you will end the class with better work flows that you can bring to your day today Work. More importantly, I want to illustrate to you why you should be using a platform as a service also known as a P s as your main tool for deploying data APS brokers. But when one of many options out there. But by the end of this course, not only will you know the core workflow in working with a P s system, you'll also know enough to advocate for bringing in one hop over to the next video to see what prerequisite knowledge you'll need to be successful in this class 2. Lesson 2: Prerequisites: with every course. Naturally, there's some assumptions I'm making about what you know. Here's what I'll be assuming for this course. Firstly, I'm assuming that you either have a data app that is Web ready locally, or that you're planning on building one. Whether this is a flask app that you've built or a stream lit app that you've created, you should know how to host it, at least on your local machine, and access it through the Web browser For this class. We're going to build a simple, stream lit app that has some interactive elements. But because the focus is on deploying the app, we won't be looking too deeply into stream lit or building a complicated app. Secondly, I'm assuming that you have a get hub account and that you're familiar with the use of get. If you aren't familiar with get fret not, I will have exact get commands that you can enter at the same time. They're really great courses on skill share that will allow you to pick up get to, so be sure to check them out. Thirdly, I'm assuming that you have the anaconda distribution of python installed on your machine for data scientists. The Anaconda distribution of python is the best way to get python onto your system as it provides the ability to create isolated and independent environments. For each of your project, this is considered programming. Best practice. Finally, you're going to need ah Hiroko account. Now, if you haven't gotten one, go ahead and sign up for a free tier account at Hiroko dot com. You won't have to pay to sign up. In fact, they don't even ask you for a credit card, though. If you do sign up and add a credit card afterwards, the free tier benefits are a little bit more generous. And just to clarify, you don't get charged as long as you stay within free tier limits. Are you ready to learn how to get your app deployed? I'm eager to share to Let's get going 3. Lesson 3: Create Repository: this section is optional. If you've already got an app running and its source code is stored on, get hub now that's not the case. Follow along. Firstly, going to get hub and create a new repository. Let's call it Demo Stream lit Harajuku. We're going to initialize it with the read me and a python. Get, ignore and finally add a license. Read Mies are super important as you can let the world know what about what your project is . So don't skip out on this step. The get ignore is also very important. You want to use it to ignore, automatically compiled and generated files, and it's a very good get practice toe. Have a get ignore in your repository. Finally, I choose the M I T license because everything we're doing here, there's nothing proprietary. So let's make it all nice and open. Source. Go ahead and click the button and create the repository. Now the next thing you want to do is to clone the repository locally, click on the big green button on the right and clone it down using your favorite method. In my case, I have ssh based access set up, so if you haven't gone it set up before. I highly recommend that you do so because it is the most secure way to push and pull source code to and from get hub. Otherwise, you can use https, which is fine as well, But you'll probably have to enter your password each time you push code. Unless you do it proper. Set up for that with the address copied to my clipboard. Let's now clone it locally. Switch over to the terminal and paste in the command. Get clone and paste the address over there. Now that it's cloned, I'm going to navigate into the project directory and do one final infrastructure piece that is to create a condo environment specifically for this project. Head over to the next video toe, learn how to do this. 4. Lesson 4: Create Development Environment: we're going to use Kanda environments to build our development environment. Because Kanda is the de facto environment management tool for data scientists, it's considered best practice toe have one condo environment for project, and the reason for this is to minimize the chances of different projects needing different packages or worse versions of the same package resulting in environment conflicts. As such, one environment per project helps minimize the chances of environment pollution between two projects. So to create a condom environment will specify using an environment that yeah mo file. Let's create it at the terminal by doing nano environment dot Why am L hit? Enter now. Inside the file. Let's add the following lines. Firstly, we're going to specify the environment. Name to be demo stream lit. Roku. I like to keep my environment names identical to my project names because that means there's one less thing for me to keep track off next up. We need to specify from which channels we want to pull down our packages. At this point in time, in 2020 most of the condo world has coalesced on pulling packages from Kanda Forge, so that's the exclusive place that we're going to pull our packages from. Finally, we need to specify what packages we want inside the environment or otherwise known as the dependencies. And for this, we're going to specify the following. We're gonna do Python version 3.8 the latest version that stable. We're gonna add the condom package Manager binary inside the environment when add in some additional things that are pretty standard to the data science world. So we have pandas, Matt plot lib, Numb pie, CYP ice. I could learn. Finally, we're gonna add Pip as an explicit dependency. And that's because we need to install Stream let via pip. Extremely. It is not yet available by conduct, so therefore we need to install Pip into the environment and listed as an explicit dependency. This is best practice that the condo developers have recommended. Now, now that we've got Pip and listed as a dependency, let's add the pip install a ble dependencies. We do pip colon and the next line stream lit once we're done, will now create the new environment. So let's exit the text editor back at the terminal. Let's type Kanda and create minus F environment. Thiemo A condom will go ahead and pull down all the necessary packages to create the environment. Now I have some automation set up that allows me to automatically activate an environment anytime I enter a directory with an environment foul. In your case, if you haven't set up this automation peace yet, you can activate the environment manually by typing Kanda. Activate demo stream. Let her Roku. Now we're ready to go and make our stream lit AP head over to the next video to get a stream lit app up and running. 5. Lesson 5: Create App: Let's now get a simple stream lit app up and running. We're going to create a simple app. Nothing too fancy as the main point here is to show you app deployment concepts. First off, let's create a file called app dot pie by typing Nano AP Top I at the terminal There's nothing particularly fancy about the name app dot pie as you can name it anything you want . Now that we're in the text editor, let's add a few lines to build up the app. Firstly, we need to import stream lit. We usually do it. Import stream lit as S T. We then add a title, my stream lit AP and then for user interaction. We're gonna add a button with the label, Click me and interact such that, if it's clicked, will show off some balloons. Let's now save the app to disk, so we do that with control X. Then why then enter? Now let's run the app simply to make sure that it works. At the terminal, we type stream lit run app dot pie. You'll see what address in port you have and that you can head over to preview the app. I've got mine over here, so let's copy it over. Go to the browser paste in the address and in a few moments, perfect. The app is loaded and it's working as expected. Take a look at those balloons. That was a really great move by the stream. Let developers, let's now head back to the terminal as there's one more thing I'd really like to explain. That is, you should know which port the stream lit app is served up on her Roco by default. It is set by an environment variable called Dollar Sign Port. Now, as with all environment variables, Weaken said it before we run the APP. And that's what we're going to do now to simulate what things will look like when we run on Hiroko. So first off, let's shut down the server by typing control. See then, at the terminal, we can run stream lit with a configured port by typing export port equals 8504 and then typing stream lit. Run ap dot pie server dot port dollar Sign port, and that allows us to interpret late 8504 into that second command hit enter and to confirm that everything's working, you'll see that we're now running on port 8504 rather than the original 8502 Now that we're done with a stream lit AP and know how to run it on different ports, let's go on to configuring Hiroko to deploy our app. 6. Lesson 6: Configure Heroku: awesome stuff. I'm super glad that you made it this fire. Stay the course with me. As in this video, I'll be showing you how to connect her Roku to your get hub repository. The first thing we're going to do is to create a new app, log into her Roku and then go to your personal dashboard at dashboard dot Hiroko dot com. Now in the top right hand corner, click on new, then select. Create new app. Next up, give your app a name. This name will become part of the URL. So if you give a name called my project, then you're you are el will be my project dot Hiroko app dot com. As is my habit, I have a preference for naming things consistently, so that means I'll be calling this demo stream lit Roku for a simple, standalone app. You don't need to worry about the rest of the options presented. Let's go ahead and click. Create app. Now that we've created the APP, you'll see that we've landed on the main app page specifically in the deploy tab. Under the deploy tab. There's this section called Deployment Method and there were going to connect to get up. So go ahead, click on the button. Connect to get hub. Now we're going to search for our project repository. You'll have to make sure that Hiroko has access to the teams and repositories that you have access to on get hub. So if you haven't done that yet, go ahead. Positive video and follow the procedures there. Once you're done with that search for the repository, in my case, it's going to be identical to the APP name, so we'll search for it using demo stream lit. Roku, we're going to connect it toe Hiroko. Now, the final thing we want to do is enable automatic deploys from get hub. You'll definitely want this. Any time You have a change to the master branch of your repository, Hiroko will pull in the latest changes and deploy them. Now, we'll keep the weight for see eye to pass before deploy off because we don't have a continuous integration. See, I system set up. Yet later on, you can set up one which will check all of your code for correctness and passing tests. If you turn on this option later than Hiroko will wait for all of your tests to pass before deploy, and this is a super highly desirable thing. Finally, click on the enable automatic deploys button cool beans. Now that we've configured Hiroko to continually deploy our app, hop over to the next video so that you can see how to configure your app to be deployable on her Roku. 7. Lesson 7: Deploy App to Heroku: This is the video that we've all been waiting for. We're now going to add the configuration files that will get her Roku to deploy our app. Are you ready? So am I. Let's get going. Firstly, we're going to add a requirements, not txt file. This will list all of the packages that are Project depends on Roku will use the requirements dot txt file toe automatically determine that this is a python project and build it accordingly and to download all of the specified dependencies of the project. Let's create the foul will go nano requirements dot txt. Now let's add in the dependencies that we want in this case, our app on Lee Import Stream lit So we will add stream lit toe our requirements dot txt file. We'll also pin its version. Now Pinning versions is extremely important to guarantee continual operation of the app even after new dependency releases have been made This way, you, the app developer, gets to control when you upgrade your dependencies buying you time to fix changes before they break your app. So we're going to pin our version of stream lit to 0.59 which is one of the latest versions of Stream Let Out There. All right, let's save this part of the file So control X y enter. Secondly, we're going to add a set up script that helps us configure our run time environment. Let's do Nano set up that s h and then type in the following first things. First, we're going to create a directory called dot Stream lit inside the home directory of Hiroko's runtime environment. So M k D I. R. Minus p until the slash dot stream lit next up, we're going to put in a configuration file in that newly created stream lit folder. So let's start typing Will do echo, quotation, mark New line and then in square brackets server in new line. And then we'll do headless equals. True. This is little caps, all right? And then we'll also do enable capital C o. R s equals faults. And then we'll finally type port Sorry and a bull course. And then finally port is equal to dollar sign port all caps and then we'll close the quotation mark and finally will pipe that output to Matilda slash dot stream lit slash config dot Tamil. Now let's save the file. And let's explain a little bit what we've done over here. Okay, so we've added a configuration file, and it's gonna be called stream lit slash conflict. That tunnel, What we're allowing stream what to do is to first run headless. Meaning that we're not gonna, uh we're not going to allow for any opening of browsers. Secondly, we're gonna disable cross origin resource sharing. That's what cores stands for. Finally, we're gonna get stream lit to serve up the app on the port environment. Variable. If this looks familiar to you, it definitely should. Because we talked about the port environment variable when we first previewed the app locally on our machine. Okay, let's save the file to disk. So Control X and then we quit. And so now we're gonna add one final file, which is called a proxy file. Yes, and Prock file is typed in without any file extension. So Nano Brock file and let's edit this guy over here. We're gonna type in only one line and follow me along, so it's gonna be Web colon s h set up dot s h and then double ampersand stream lit, Run, uh, app. dot high and, well, let me explain a little bit about what's happening on inside here. So first off the profile is a special file that Hiroko uses to determine what process type to run. Hence the name Prock in profile. Our app is going to be a Web process, since we're going to access it over the Internet. That's what the Web Colon stands for. Everything after the colon are the commands needed to get the app set up. So we first run the bash script, set up that s age and then finally we run stream lit by calling on its stream lit run apple pie. Now, you might be wondering, Why do we have to keep running the set up screen? Well, this is because her Roku provides only an ephemeral or temporary file system that gets erased on every app reboot, which means on every app rebuild, we have to rewrite the configuration file for stream lit. And so this set up that S H script gives us a convenient way to reference all of the steps that are needed to build the app in a clean fashion. And this is actually a good practice because by guaranteeing a clean rebuild of the app each time the APP is restarted. There no leftover side effects from old app runs that can affect the newly started at. So you're always guaranteed to have a freshly running application. All right, so now let's save the Prock file control. Oh, enter and then control X. And now we're going to push our files to the remote repository. So we're gonna do get ad Perak foul requirements dot txt and set up dot Shh. The next thing we're gonna do is we're gonna do, get commit. So we're gonna commit the files into the repository. Let's do committing fouls for her Roku build. You'll also notice we haven't yet committed our APP and environment Thiemo file. So we're gonna do that next, Right after this. So will exit. The Nano Tex editors will control X control control X Y and then enter. Then we'll do it. Get status one more time adding the rest of the files can't forget to add Get up. We can't forget to add abduct pie so we'll do a get commit for that one and will say adding application script to write it the control oh, control X and then one Final one, which is the environment file. Get add environment that, um oh, and get commit and will say a committing environment Development environment file. All right, finally, let's push the changes up to get hub using get push. At this point, we're kind of done at the terminal. And so we're gonna head over now to the browser and go to our app dashboard. This time, we're now going to look at the activity tab and you'll notice that the build has just started happening so we can look at the build process in real time. As you can see, thanks to the Prock file and requirements dot txt Hiroko is automatically determined that this is a python app, and it started pulling down all of the dependencies that this python at requires. So we'll give it a moment to do what it needs to do. Okay, folks, take a look at this. Now we see that Hiroko has successfully built the app and it's released it to this euro. Exactly our app. Ural Demo stream that Hiroko doctorow co app dot com. Let's go ahead. Copy that You Earl and head over there, paste it hit. Enter and bingo. Look at that are up. Our app has been deployed. You click on Click me the balloons Work just is expected. 8. Lesson 8: Concepts Review: Now that we've got an app working on her Roku, let's take a step back and review some of the core ideas we went through in this class. The most important take away that you should have picked up is the get based workflow for deploying an app on a platform as a service system that involves placing your app in a git repository and enabling automatic deploys of the master branch on every push to master. By leveraging a platform as a service system and the get based workflow with a lot of automation invested, you no longer have to concern yourself with manually deploying your app and and can instead focus on improving it along the way. I also showed you about Conda environments. The general concept of an environment is super important for the reliability of the software we make and for reproduce ability of our machine learning projects. In particular, I showed you how to easily set up a condom environment with a configuration file environment that Yemen now simply to jog your memory. An example file is shown on the screen here. Having the habit of making isolated environments will help you with reproduce ability and avoid package version conflicts with other projects. And here's a pro tip for you. If you notice that most of your projects use more or less the same suite of base packages, don't be afraid to maintain basically an opinionated Kanda Environment file that you can copy and paste from project to project. We also set up a few other configuration files for AP deployment. Here we used a requirements dot txt file and approx file. The requirements dot txt file declares all of the dependencies of the APP with pinned versions as best practice, while the prop file is something that was, say, once, Hiroko specific. But now many platform as a service systems have adopted it. After all, Roku was one of the earliest platform as a service players. Now, if you use other PS platforms, they may have their own conventions. But the core idea of using configuration files to declare the resource is and dependencies of project is quite commonplace. And in fact, you might say the environment that yeah, mo fell isn't exactly the same mold. All of this is a long winded way to show you how a platform as a service can be really helpful. If we didn't use a platform as a service system like Roku, we would be left configuring many things, the most nebulous one being the Web server, a pasha, engine X and all of that stuff. Many of US data scientists just aren't trained in the Web, so having opinionated automation to help smooth over the process of deployment is a wonderful thing. Now, in the interest of showing you the key workflow for AP deployment, I didn't cover how to build a more complex stream lit AP or how to pull in pre trained machine learning models or how to do more complex builds that pull a container from a centralized container registry. That said, if this is something you're interested in learning, leave a comment as you review the class. And, yes, don't forget to leave a review because your feedback will help me make better learning content for you. 9. Lesson 9: Class Project: Now it's your turn to go ahead and try making something as your post class task. I'm going to encourage you to practice with your own project. If you have a data app and you're simply lacking the final step of deployment, this class should have given you the necessary steps to make your app deployment a reality . If you've not made a data app, then I'd encourage you to take what you've learned in this class and apply it to a new project that you've kick started and then put it up on her. Roku. Once you put it out there and shared it with the world, it becomes a permanent part of your skills and projects portfolio, which could be so helpful in landing your next data scientist role. Thanks for joining me in this class. If you have any feedback or questions, be sure to leave a message below, and I check into skill share once a week to answer questions in particular. Let me know what else you'd like to learn. Thanks again. Have a great time deploying