Integration with flask app

Hello,
I am trying to integrate streamlit app with flask app. what would be the recommendations.
I also want to save the rendered html file from streamlit so i can use flask.render_template to show the interative streamlit app inside flask.

is there an option to save it to html ?

3 Likes

Hey @qxlsz, thanks for checking out Streamlit!

Streamlit runs its own web server via the Tornado framework, and there’s no good way to embed a Streamlit app inside a Flask server.

(Serving an interactive Streamlit app via flask.render_template isn’t feasible, because Streamlit apps are not static; when you interact with your Streamlit app, it is re-running your Python code to generate new results dynamically.)

You could, however, run Streamlit alongside a Flask app (or possibly embed your Streamlit app inside an <iframe> that’s served from your Flask app). But before I send you too far down a rabbithole, can you explain in more detail what you’re trying to achieve?

1 Like

Would there be a possibility in the future to have an ability to host endpoints via the same Streamlit app? This could help merge / migrate Flask or other types of app into streamlit - I hope I’m making sense. My question is similar but I want to also use the same server as an endpoint server/host.

Or do you recommend that we host a separate endpoint server and keep it separate from streamlit server?

I think my query got answered here Streamlit restful app

It could be interesting to have the possibility as Bokeh does to use the function ‘server_document’.

In bokeh in flask framework you could ‘call’ this function
app1 = server_document(‘http://localhost:5000/bokehapp1’) and then you can send app1 as variable of your flask template
render_template(’'index.html",app1=app1)

and in template {{app1}}

The app lives in a loop server from bokeh.server.server, and you can create app1, app2, app3 without problems as a graph api to your flask page.

As always is an idea. But integrating this type of tools in solid webframeworks (like django, flask, etc
) it’s good idea as it let you develop solid webpages, and integrate advanced dynamic tools when required.

Thank you!!

Hi @f1se4, welcome to the Streamlit community!

You’re right, there are always ways that we might do things differently, but then it stops being Streamlit! Meaning, if you find Streamlit preferable to Django, Flask, Bokeh because it’s really easy to get started, then making Streamlit more like those other projects (which are all great in their own right!) brings us back to the original reason why Streamlit was created in the first place :slight_smile: