Multiple apps from a folder/file list

This is a great app. Thank you for your hard work.

Wondering if it is possible to render all python scripts as apps from a folder or file list?

1 Like

Hi Rahul_B!

While Streamlit doesnā€™t come with support for running multiple apps from a given folder, you can always write your own Python script to do that. Which is exactly what I did below :smiley:

Try this:

  1. Save the file below as run_all.py:
    https://gist.github.com/tvst/f63ab0d34a20bcae86504812cf3de32c

  2. Run this on a terminal:

    python run_all.py some/folder/
    

And thatā€™s it! Let me know if this works out for you.

6 Likes

Thanks @thiago.

run_all.py script runs each app as a seperate port. Was wondering if it is possible to run multiple apps in single port and with links to each app.

Oh, I see what you mean.

This isnā€™t supported right now in the exact way youā€™re describing. But you can make a Streamlit app that has a selectbox that lets you choose other apps to run inline in that same browser window. This means the selectbox will always be visible, even when you go into other sub-apps.

See this Gist: https://gist.github.com/tvst/f13b24198e256c1c4d9b5ccbc6991cc2

6 Likes

Hi Rahul

Iā€™ve created a multipage app here https://github.com/marcskovmadsen/awesome-streamlit.

You can take a look at the src/app.py file and the src/pages folder for inspiration. If you can improve it even further I would like to know.

Thanks.

2 Likes

I am using something based on the gist @thiago posted, however streamlit doesnā€™t detect changes in the file which has been opened and execed. Is there a way to make this work?

1 Like

Hi @Zach_Dwiel, Iā€™ve updated the Gist to support this.

The basic idea is that Streamlit looks at all modules in sys.modules whose source file lives in the main fileā€™s folder (including subfolders). So in the Gist above I now add modules to sys.modules just so Streamlit will watch them :smiley:

2 Likes

that did the trick, thanks!

These Gists are pretty smart, thank you!

To run multiple streamlit apps on the same server in a more robust manner (and not inline), please see streamlit-launchpad which runs each app in a separate process and at a sub-folder URL.

So if I run streamlit-launchpad on a folder, the root at / shows a basic list of available apps. If I click into /app1.py/ it will launch the app1.py streamlit in a new process (and on a new port, but proxied through).

As ever, hopefully Streamlit will build this functionality natively soon!

3 Likes

Iā€™m facing the same problem. @danlester will your package work if ran as an entrypoint of a served docker container? Iā€™m asking because I noticed in the code the usage of localhost and it made me a little worried.

Ideally, indeed, streamlit should expose a functionality to serve different apps. I cast my vote for that.

2 Likes

Yes, streamlit-launchpad runs well in Docker.

Here is a basic image with streamlit and launchpad installed - mount your app folder to /app in the container as given in the example below:

https://hub.docker.com/r/ideonate/streamlit-launchpad

And another one with some more scientific Python packages preinstalled:

https://hub.docker.com/r/ideonate/streamlit-launchpad-scipy

The use of ā€˜localhostā€™ within the container is when the launchpad application starts the Streamlit sub-processes, as these are designed to run entirely within the container. Web traffic externally to the container needs only to be forwarded to the launchpad app itself, which then proxies to the relevant (localhost) Streamlit processes.

1 Like