Guide: Hosting multiple streamlit apps on Heroku and nginx based authentication

Hi everyone, over the last few months I’ve been using Streamlit more and more as it’s a great way to create demos and showcase algorithms.

My main needs have converged to:

  • Being able to host the apps on Heroku, since it’s the main platform I use.
  • Host multiple apps on the same Heroku application, since it’s more convenient to have them all on the same place.
  • Restrict user access via some form of authentication.

All these issues have been addressed here in the forum several times but I found the info to be somewhat disperse and not always easy to replicate. So I decided to do a small guide starting from zero.

Comments and pull requests are welcome.

7 Likes

Looks awesome, thanks for writing this up and sharing :+1:

@Alexandre_Domingues Do you mind saying something about what benefits you get from putting the Nginx server as a proxy in front of Streamlit?

I understand you’re using Nginx for authentication. Are there other benefits to going through Nginx (vs exposing the Streamlit port itself to users)?

My initial approach was to run each streamlit app independently and use nginx to handle routing. E.g. launch streamlit run app1.py and streamlit run app2.py and then use nginx to access the apps via http://somehost/app1 and http://somehost/app2.

The advantage of this approach is that each app is truly independent. However this involves dealing with the routing itself (i’m a noob with nginx) but also starting a tornado server for each app, which seems a waste of resources, specially in limited machines (as is the case of Heroku’s free dynos).

So I ended up with the curretn approach, using Nginx only for authentication and running all apps as the child of a parent app.

Thanks! That makes sense.

@Alexandre_Domingues
Does this support external users sign up and login using google auth too?

Nop, the authentication is very basic.

Thanks @Alexandre_Domingues

Any suggestion on what the best way is to add login with google to a simple streamlit app?
Looked at Auth0 but I don’t think it supports it. (At least that is what their forum says).

Thanks