{"id":5504,"date":"2020-10-20T17:16:23","date_gmt":"2020-10-20T17:16:23","guid":{"rendered":"https:\/\/data-science.gotoauthority.com\/2020\/10\/20\/deploying-streamlit-apps-using-streamlit-sharing\/"},"modified":"2020-10-20T17:16:23","modified_gmt":"2020-10-20T17:16:23","slug":"deploying-streamlit-apps-using-streamlit-sharing","status":"publish","type":"post","link":"https:\/\/wealthrevelation.com\/data-science\/2020\/10\/20\/deploying-streamlit-apps-using-streamlit-sharing\/","title":{"rendered":"Deploying Streamlit Apps Using Streamlit Sharing"},"content":{"rendered":"<div id=\"post-\">\n<p><b>By <a href=\"https:\/\/tylerjrichards.medium.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tyler Richards<\/a>, Data Scientist @ Facebook<\/b><\/p>\n<div>\n<img src=\"https:\/\/s8.gifyu.com\/images\/1_1OkCXEqnscCdBK_kvNilfQ.gif\" alt=\"Figure\" width=\"100%\"><br \/><span><\/p>\n<p>Image by author<\/p>\n<p><\/span>\n<\/div>\n<p>\u00a0<\/p>\n<p>Over the past couple of weeks, I\u2019ve been playing around with a new Streamlit feature called Streamlit sharing, which makes it super easy to deploy your custom apps. I\u2019m going to go through a bit of background first, so if you want to see the docs for Streamlit sharing to get started you can find them\u00a0<a href=\"http:\/\/docs.streamlit.io\/sharing\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>.<\/p>\n<p>\u00a0<\/p>\n<h3>Streamlit background<\/h3>\n<p>\u00a0<br \/>For a bit of background, Streamlit is a framework that lets you quickly and confidently turn a python script into a web app and is an incredible tool for data scientists working on teams where they need to quickly share a model or an interactive analysis, or for data scientists working on personal projects they want to show the world. Here\u2019s a\u00a0<a href=\"https:\/\/docs.streamlit.io\/en\/stable\/\" rel=\"noopener noreferrer\" target=\"_blank\">Streamlit beginner tutorial<\/a>\u00a0if you want to try it out!<\/p>\n<p>I\u2019ve been using Streamlit for the past ~6 months, and it\u2019s been\u00a0<strong>so<\/strong>\u00a0useful. Previously, if I knew I wanted to make a web app at the end of a project, I would always opt to switch to R for the wonderful R shiny framework, even though I am a much better python programmer than an R one. Going through Django or flask is just so much development friction to take on that it\u2019s rarely worth it for a personal project and always takes too long for anything at work. But after using Streamlit, I now not only had options but found myself preferring python+Streamlit to R+shiny.<\/p>\n<p>\u00a0<\/p>\n<h3>Streamlit sharing<\/h3>\n<p>\u00a0<br \/>This brings me to a couple of months ago. I started a\u00a0<a href=\"http:\/\/www.tylerjrichards.com\/books_reco.html\" rel=\"noopener noreferrer\" target=\"_blank\">DS project<\/a>\u00a0focused on analyzing reading habits using data from the\u00a0<a href=\"http:\/\/www.tylerjrichards.com\/books_reco.html\" rel=\"noopener noreferrer\" target=\"_blank\">Goodreads<\/a>\u00a0app. I decided to try Streamlit out, and it turned a multi-day long process of getting a Django\/flask app running well locally into one that took around a half-hour for local Streamlit use. It really is as easy as throwing your analysis into a script, and calling Streamlit functions whenever you want to put a graph, widget, or text explainer on the app.<\/p>\n<p>However, the most annoying process on Streamlit was the deployment and management process. The\u00a0<a href=\"https:\/\/towardsdatascience.com\/how-to-deploy-a-streamlit-app-using-an-amazon-free-ec2-instance-416a41f69dc3\" rel=\"noopener noreferrer\" target=\"_blank\">tutorial I followed<\/a>\u00a0was straightforward, and didn\u2019t take that much time, but was fairly extensive. It required launching an ec2 instance, configuring SSH, using tmux, and going back to this terminal every time you wanted to change anything about your web app.\u00a0<strong>It was doable but annoying.<\/strong><\/p>\n<div>\n<img src=\"https:\/\/i.ibb.co\/v4ByZyw\/1-Qtz-Wk-SFv-BBJdo8-YWmpvg-Lw.png\" alt=\"Figure\" width=\"100%\"><br \/><span><\/p>\n<p>Image by author<\/p>\n<p><\/span>\n<\/div>\n<p>\u00a0<\/p>\n<p>A few weeks ago, Streamlit saw my Goodreads app and asked if I wanted to test out their Streamlit sharing beta, which was supposed to remove the friction explained above. I, obviously, gave it a shot.<\/p>\n<p><strong>All I had to do was:<\/strong><\/p>\n<ol>\n<li>Push my app to a Github repo\n<\/li>\n<li>Add a requirements.txt file that listed all the python libraries I used\n<\/li>\n<li>Point Streamlit to my app via the link to the repository\n<\/li>\n<li>Click Deploy\n<\/li>\n<\/ol>\n<p>It genuinely was\u00a0<strong>that easy<\/strong>\u00a0to figure out. I had sectioned off a couple of hours to figure it out, as I expected various bugs to pop up (it is in beta!), but it took me fewer than 10 minutes to get it up and running.<\/p>\n<p>I currently have three apps running, one is a test app, the second is the\u00a0<a href=\"https:\/\/share.streamlit.io\/tylerjrichards\/book_reco\/master\/books.py\/+\/\" rel=\"noopener noreferrer\" target=\"_blank\">Goodreads book recommendation app<\/a>\u00a0I mentioned earlier, and the third is an\u00a0<a href=\"http:\/\/www.tylerjrichards.com\/survey.html\" rel=\"noopener noreferrer\" target=\"_blank\">interactive analysis<\/a>\u00a0of a tech survey that I spun up (from idea to functioning and deployed web app) in around an hour and a half.<\/p>\n<p>Switching to Streamlit sharing has also saved me the ~$5 a month AWS bill, which I would gladly pay for this feature just for the savings in time spent on deployment alone.<\/p>\n<div>\n<img src=\"https:\/\/i.ibb.co\/5G50y24\/1-cuw-GOwmib-KJLtutcvnb-Fa-A.png\" alt=\"Figure\" width=\"100%\"><br \/><span><\/p>\n<p>Image by author<\/p>\n<p><\/span>\n<\/div>\n<p>\u00a0<\/p>\n<p>If I wanted to try out a new app, I could just click the new app button, point it to my repo, and they would handle literally everything else.<\/p>\n<div>\n<img src=\"https:\/\/i.ibb.co\/DgWQrHD\/1-HFMHb-H5-FUO-x-Wnk8j-qe-A.png\" alt=\"Figure\" width=\"100%\"><br \/><span><\/p>\n<p>Image by author<\/p>\n<p><\/span>\n<\/div>\n<p>\u00a0<\/p>\n<p>If your Streamlit app uses any other packages, make sure to include a requirements.txt file in your repo \u2014 otherwise you\u2019ll immediately get an error when deploying. You can use something like pip freeze to get requirements but that will give you all of the packages in the environment including those that you don\u2019t use in your current project. And that will slow down your app deployment! So I\u2019d suggest using something like pipreqs to keep it to just the core requirements for your app.<\/p>\n<div>\n<pre><code>pip install pipreqs\r\npipreqs \/home\/project\/location<\/code><\/pre>\n<\/div>\n<p>If you have requirements for apt-get, add them to\u00a0<code>packages.txt -<\/code>, one package per line.<\/p>\n<p>\u00a0<\/p>\n<h3>Conclusion<\/h3>\n<p>\u00a0<br \/>So as a wrap-up, Streamlit sharing has saved me $ on both a development time saved and hosting cost basis (shoutout to the VC funds that make this all possible), has made my personal projects more interactive and prettier, and has taken away the headaches of deploying quick models or analyses. No wonder I\u2019m a Streamlit fan.<\/p>\n<p>Want to see more of this content? You can find me on\u00a0<a href=\"https:\/\/twitter.com\/tylerjrichards\" rel=\"noopener noreferrer\" target=\"_blank\">Twitter<\/a>,\u00a0<a href=\"https:\/\/insignificantdatascience.substack.com\/p\/starting-a-data-science-newsletter\" rel=\"noopener noreferrer\" target=\"_blank\">Substack<\/a>, or on\u00a0<a href=\"http:\/\/www.tylerjrichards.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">my portfolio site<\/a>.<\/p>\n<p><strong>Happy Stream(lit)ing!<\/strong><\/p>\n<p>\u00a0<br \/><b>Bio: <a href=\"https:\/\/tylerjrichards.medium.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Tyler Richards<\/a><\/b> is a Data Scientist at Facebook.<\/p>\n<p><a href=\"https:\/\/towardsdatascience.com\/deploying-streamlit-apps-using-streamlit-sharing-16105d257852\" target=\"_blank\" rel=\"noopener noreferrer\">Original<\/a>. Reposted with permission.<\/p>\n<p><b>Related:<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.kdnuggets.com\/2020\/10\/deploying-streamlit-apps-streamlit-sharing.html<\/p>\n","protected":false},"author":0,"featured_media":5505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts\/5504"}],"collection":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/comments?post=5504"}],"version-history":[{"count":0,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/posts\/5504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/media\/5505"}],"wp:attachment":[{"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/media?parent=5504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/categories?post=5504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wealthrevelation.com\/data-science\/wp-json\/wp\/v2\/tags?post=5504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}