Hosting streamlit on github pages

Hello devs! i am a student that just stumbled upon this library and curious if i’m able to host it on github pages :smiley: otherwise is there any other free-tier platform that I can host and deploy this app on a website? Would love to give it a try!

1 Like

@lyqht you can deploy your app on heroku. I think that a few folks, including myself, have been able to successfully deploy there.

Data Explorer App on heroku

1 Like

Hi @lyqht

Since Streamlit apps aren’t static (that is, they need to run in Python), Streamlit apps cannot run on a static-file host like Github pages. So @gabe_maldonado is right: what you need to do is pick your favorite platform and host it there.

Most hosting platforms are paid (AWS, GCP, Azure, DigitalOcean, etc). The only exception I can think of is Heroku, which has a free tier, albeit with some strong limitations.

People in this forum have used all of those in the past, so search around and ask them questions if you need help with a specific platform. And something else that may be useful is this Streamlit user’s article detailing the steps he too to deploy on AWS EC2: https://medium.com/@pokepim/deploying-streamlit-app-to-ec2-instance-7a7edeffbb54

3 Likes

Thank you for posting your example! :slight_smile: it gives me more confidence to try out this library!

Dear @gabe_maldonado, can you share your steps for deploying to heroku? I’m quite new to deployment, i apologize. Currently I just tried out two hours trying to deploy on heroku and i’m facing the following issues in the logs for a very simple app that is only reading data from a .csv file (yes really nth else, not even charts yet).

First Issue: no web processes

heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=cds-playstore-analytics.herokuapp.com request_id=06fae25b-d1ba-4bb4-838f-84d3f88d3e1f fwd="138.75.242.168" dyno= connect= service= status=503 bytes= protocol=https

With some googling, i fixed it by incorporating a Procfile with the following:
web: gunicorn website.wsgi --log-file -

Second Issue from herokulogs --tail: ModuleNotFound: No module named 'app'

I don’t understand what is the proper folder structure or configuration that I’m missing out for deployment. Pls help! I’ve tested the streamlit locally its awesome but if I can’t deploy it then there is no real benefit for me to use Streamlit over just using jupyter notebook :confused:

1 Like

Hey there @lyqht seems like you’re making some progress. I am making the assumption that you have git and heroku cli already configured in your machine so you’re good to go there.

The way that I made it work is as follows:

  • Used VSCode
  • Created a virtual env and installed all required packages
  • Created an app.py file where I coded the sample app.
  • Once the app was running fine on my local machine I went ahead and deployed by:
  • Freezing requirements and creating a requirements.txt file
  • Creating a setup.sh file
  • Creating a Procfile

Type the following to your setup.sh file:

Change your Procfile to:

And then use the git and heroku workflow to create, commit, and push your app.

Hope this helps and let me know if this works for you.

I’m thinking about writing a tutorial on this-- I just have to find some free time.

GM

6 Likes

Thanks for the writeup for the steps you have done! I have followed your steps to create a Procfile and setup.sh. I have to restart the dynos a few times to get it to run on the new Procfile as well :confused:

This is the new error i see in the logs


Why would the web process fail to bind to $PORT?

Are you sure your setup.sh is running?
I would try to echo $PORT on the setup.sh and then check the logs to compare it with the port that streamlit is binded to.

Hey thanks for helping out!
I do see this in my logs:

Starting process with command `sh setup.sh && streamlit run website/main.py`

I’ve tried to add echo $PORT to the setup.sh but it seems that it is not producing the $PORT in the logs.

This is my setup.sh following @gabe_maldonado , without the credentials part, may i ask what is wrong?

echo "\
[server]\n\
enableCORS=false
headless = true\n\
port = $PORT\n\
" > ./.streamlit.config.toml

echo $PORT

You have a couple of typos. Here’s mine:

mkdir -p ~/.streamlit/

echo "\
[general]\n\
email = \"your-email@domain.com\"\n\
" > ~/.streamlit/credentials.toml

echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml
4 Likes

Thank you! I got it to deploy onto heroku now! :slight_smile:
I see that my file is missing the \n after the enableCORS=false, but somehow it works for @gabe_maldonado?

1 Like

You were missing the line break but you were also redirecting to the wrong config file (./.streamlit.config.toml). I’m not sure but probably @gabe_maldonado’s solution was inspired by my initial post here, which also has the line break.

1 Like

Ah i see! Thank you :smiley:

1 Like

Glad you got it to work, @lyqht. I bet it felt awesome!
My file is missing the \n but somehow it works without throwing any errors. And thanks to @Alexandre_Domingues as well for helping out.

Yeap :slight_smile: I’m really thankful to the community.

1 Like

Thank You gabe_maldonado.
I was also getting the same error “h14” after deployment then I just added setup.sh & Procfile as you mentioned Its worked for me. Now running my streamlit app in heroku

1 Like

Hi Alexandre,

I´m a newbiee to heroku and streamlit. I would like to ask you a help to publish a python code by heroku. Could you show, send me a example ?
Thanks,

Silvio
silviolima07@gmail.com

I can already picture the command:
> streamlit hk-deploy
This would do just a few things: check that one is logged into heroku, that there is a requirements.txt, setup.sh and Procfile, then doing the right git push. If any of the required things are missing, sending them to the heroku tutorial. Of course I only just looked at the heroku tutorial for the first time 5 minutes ago, but subprocess should be able to do that work if the needed files are all in place.

3 Likes

Yeah i think it will be great to include this command! :smiley: