Skip to content
← Back to Community
How to use streamlit in Repl.it
Profile icon
NicolasRemond

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.

Answered by ShrutiAgarwal11 [earned 5 cycles]
View Answer
Voters
Profile icon
JonathanButler
Profile icon
Tonialg
Profile icon
cldscchttn
Profile icon
NicolasRemond
Comments
hotnewtop
Profile icon
ShrutiAgarwal11

Hey @NicolasRemond 👋.
I've recently used streamlit in replit and I think you can follow the same steps given below :

  1. Create a new repl with Python

  2. Write your streamlit code in main.py and then rename the file to streamlit_app.py

  3. Create a new file called, requirements.txt , & add the streamlit latest version and other packages versions you have used in your streamlit_app.py file!

  4. Configure the run command inside .replit file --->
    run = "streamlit_app.py"

  5. Now, go to Shell area and write --->
    $ pip install streamlit
    [After some minutes streamlit will be installed!]

    [Then check whether streamlit was installed by running the command below]
    $ streamlit hello

  6. Finally, run ---> $ streamlit run streamlit_app.py
    [This will open a Mozilla browser running your streamlit App! 🎉🎈]

If you found these steps helpful for you, then make sure you upvote and share it! 😃

Profile icon
NicolasRemond

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")

Profile icon
LeonDoesCode

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`.

Profile icon
NicolasRemond

@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 ?

Profile icon
LeonDoesCode

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

Profile icon
LeonDoesCode

@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).

Profile icon
NicolasRemond

@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 ?

Profile icon
LeonDoesCode

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

Profile icon
LeonDoesCode

@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.

Profile icon
NicolasRemond

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

Profile icon
LeonDoesCode

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

Profile icon
NicolasRemond

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

image