Deploying Streamlit Apps Using Streamlit Sharing


By Tyler Richards, Data Scientist @ Facebook


Image by creator


Over the previous couple of weeks, I’ve been enjoying round with a brand new Streamlit function referred to as Streamlit sharing, which makes it tremendous simple to deploy your customized apps. I’m going to undergo a little bit of background first, so if you wish to see the docs for Streamlit sharing to get began you’ll find them right here.


Streamlit background

For a little bit of background, Streamlit is a framework that permits you to shortly and confidently flip a python script into an online app and is an unimaginable software for information scientists engaged on groups the place they should shortly share a mannequin or an interactive evaluation, or for information scientists engaged on private initiatives they need to present the world. Here’s a Streamlit newbie tutorial if you wish to attempt it out!

I’ve been utilizing Streamlit for the previous ~6 months, and it’s been so helpful. Previously, if I knew I wished to make an online app on the finish of a undertaking, I might at all times decide to modify to R for the fantastic R shiny framework, despite the fact that I’m a a lot better python programmer than an R one. Going by Django or flask is simply a lot growth friction to tackle that it’s hardly ever value it for a private undertaking and at all times takes too lengthy for something at work. But after utilizing Streamlit, I no longer solely had choices however discovered myself preferring python+Streamlit to R+shiny.


Streamlit sharing

This brings me to a few months in the past. I began a DS undertaking centered on analyzing studying habits utilizing information from the Goodreads app. I made a decision to attempt Streamlit out, and it turned a multi-day lengthy strategy of getting a Django/flask app working properly regionally into one which took round a half-hour for native Streamlit use. It actually is as simple as throwing your evaluation right into a script, and calling Streamlit features everytime you need to put a graph, widget, or textual content explainer on the app.

However, probably the most annoying course of on Streamlit was the deployment and administration course of. The tutorial I adopted was simple, and didn’t take that a lot time, however was pretty in depth. It required launching an ec2 occasion, configuring SSH, utilizing tmux, and going again to this terminal each time you wished to vary something about your net app. It was doable however annoying.


Image by creator


A couple of weeks in the past, Streamlit noticed my Goodreads app and requested if I wished to check out their Streamlit sharing beta, which was presupposed to take away the friction defined above. I, clearly, gave it a shot.

All I needed to do was:

  1. Push my app to a Github repo
  2. Add a necessities.txt file that listed all of the python libraries I used
  3. Point Streamlit to my app by way of the hyperlink to the repository
  4. Click Deploy

It genuinely was that simple to determine. I had sectioned off a few hours to determine it out, as I anticipated numerous bugs to pop up (it’s in beta!), however it took me fewer than 10 minutes to get it up and working.

I presently have three apps working, one is a take a look at app, the second is the Goodreads guide suggestion app I discussed earlier, and the third is an interactive evaluation of a tech survey that I spun up (from concept to functioning and deployed net app) in round an hour and a half.

Switching to Streamlit sharing has additionally saved me the ~$5 a month AWS invoice, which I might gladly pay for this function only for the financial savings in time spent on deployment alone.


Image by creator


If I wished to check out a brand new app, I might simply click on the brand new app button, level it to my repo, and they might deal with actually all the things else.


Image by creator


If your Streamlit app makes use of another packages, make sure that to incorporate a necessities.txt file in your repo — in any other case you’ll instantly get an error when deploying. You can use one thing like pip freeze to get necessities however that provides you with the entire packages within the setting together with people who you don’t use in your present undertaking. And that may decelerate your app deployment! So I’d counsel utilizing one thing like pipreqs to maintain it to only the core necessities to your app.

pip set up pipreqs
pipreqs /residence/undertaking/location

If you have got necessities for apt-get, add them to packages.txt -, one bundle per line.



So as a wrap-up, Streamlit sharing has saved me $ on each a growth time saved and internet hosting price foundation (shoutout to the VC funds that make this all doable), has made my private initiatives extra interactive and prettier, and has taken away the complications of deploying fast fashions or analyses. No marvel I’m a Streamlit fan.

Want to see extra of this content material? You can discover me on TwitterSubstack, or on my portfolio web site.

Happy Stream(lit)ing!

Bio: Tyler Richards is a Data Scientist at Facebook.

Original. Reposted with permission.



Source hyperlink

Write a comment