Ask coding questions

← Back to all posts
How to use streamlit in Repl.it
NicolasRemond (9)

Streamlit is a python library for creating a quick frontend really fast : https://streamlit.io/

However to run it you need to access terminal and run this command for example :

streamlit run myapp.py

I could get around this by calling the command using subprocess in the main.py, but the app is not accessible from the link provided by repl.it.

Did anyone succeed running streamlit on replit ? Any advice would be helpful.

Comments
hotnewtop
LeonDoesCode (438)

You can still run shell commands in Repl. So you can use subprocess to get the result you are looking for. You can move the code you have in main.py to a new file, and then use the main.py file to run the commands which will run streamlit`.

NicolasRemond (9)

@LeonDoesCode
I did this, but the replit is not connecting to the application. I guess it's a port problem. On which port should I start the application ?

LeonDoesCode (438)

@NicolasRemond I'll have a look through the docs quickly to see what I can find.

LeonDoesCode (438)

@NicolasRemond I switched out subprocess for os like so:

import os
os.system("streamlit run app.py")

When you run it, you now get links in the terminal. Is that what you wanted? (The links are dead by the way).

NicolasRemond (9)

@LeonDoesCode
Thanks for the help. Indeed it works (the app is running in the terminal, and as you said the links are dead).

So now the question is how to make it work and redirect the address (http://yyyy.repl.co) to the running app ?

LeonDoesCode (438)

@NicolasRemond I'll see what i can do, but wont be able to respond until later as im decorating.

LeonDoesCode (438)

@NicolasRemond I'm not to sure how to get this to work.If you want to redirect then you can press the pencil icon in the browser window, top right, to edit the redirect of the page. Don't know if that helps. Other than that I'm stumped. Sorry I couldn't help.

NicolasRemond (9)

@LeonDoesCode
Thanks for the help anyway :)
Do you happen to know which port repl.it open the page ?

LeonDoesCode (438)

@NicolasRemond I'd guess 8501 based on the url ends.

NicolasRemond (9)

@LeonDoesCode
Yes, I think the problem lie somewhere else.
The app seems running but I can't interact with it :

NicolasRemond (9)

I finally got it working. I had to disable Cross-Origin Request Sharing in streamlit, as described here

So to start the app, just use :

os.system("streamlit run app.py --server.enableCORS false")