Streamlit run in a different port and endpoint

Hello, I am trying to run my flask app and streamlit in same port
my flask has 0.0.0.0:5000/foo endpoint
and i want to run my streamlit app in 0.0.0.0:5000/foo2

is it possible ? if so how ?

Hi @qxlsz,

There are two ways to accomplish this, depending on your goals.

The more robust way to accomplish this would be to configure a web server like NGinx or Apache2 to serve as a reverse proxy that routes to different port numbers based on the endpoint names.

For example, you could put streamlit on port 8501 and your Flask app on port 5000, have your web server set up on any port you like (e.g. standard web port 80, or 8080, or 8888…), and then your requests would look like this:

Here’s a sample Nginx config by a Streamlit engineer (@monchier) that shows how to set up two Streamlit apps to be served by the same web server. You would just need to edit one of those config sections as appropriate for your Flask app.

The simpler method would be to set up your flask app to contain a page that is simply an iframe around your streamlit app.

So in that case, you’d run Flask on port 5000 and keep Streamlit on port 8501, and simply set up a Flask template with a line like:

<iframe src="http://yourdomain.com:8501"></iframe>

I hope that helps!

2 Likes

Thanks much