How to deploy multiple Streamlit apps on one subdomain?

I have a question about running one streamlit app.py in other streamlit app.py

Here is how I do
app1.py

import streamlit as st
st.write( 'This is app1')

app2.py

import streamlit as  st
st.write( 'This is app2')

Now I want to add them to
run_app.py

import subprocess
import streamlit as  st

if st.button('run app1'):
  subprocess.run(["streamlit", "run", app1.py])

if st.button('run app2'):
  subprocess.run(["streamlit", "run", app2.py])

Now I run run_app.py in command line ,

streamlit run /Users/run_app.py  --server.port 8501

it opens a web on http://localhost:8501/
when I click run app1, it open a new tab ,run app1.py on http://localhost:8502/
when I click run app2, it open another new tab, run app2.py, on http://localhost:8503/


Here comes my problem, I want to deploy this kind of case on streamlit cloud from github
When i open the streamlit app, it open run_app.py and show the page
but when I click run app1, nothing happen

So is there any special setting when deploy the case on streamlit-cloud
(I have set the requirements)

Thanks

Is there a reason you can’t use the native multipage functionally?

Hi @calvinish

As @mathcatsand had pointed out, it may be worth to explore the use of a multipage app (Create a multipage app - Streamlit Docs).

Another approach if you rather want to create 2 separate apps and want to call each of them from within your main app, you could also use Stlite Sandbox from the streamlit-extras component.

Hope this helps!

@dataprofessor @mathcatsand

Thanks, I have taken your suggestion, and achieve the case through multipage functionally

1 Like

@mathcatsand @dataprofessor
Sorry, I have a new problem when use multipage

The multipage introduce shows the example
like

β€”β€” Hello.py
β€”β€” pages
   ο½œβ€”β€”1_st_app1.py
   ο½œβ€”β€”2_st_app2.py
   ο½œβ€”β€”3_st_app3.py
β€”β€” requirements.txt

I want to run multipage like

β€”β€” Hello.py
β€”β€” pages
    ο½œβ€”β€”1_st_app1.py # st_app1 needs the files from folder app1
    ο½œβ€”β€” app1  # this is a folder
       ο½œβ€”β€”  app1.py   #  This is a python file without streamlit
       ο½œβ€”β€”  app1.json
       ο½œβ€”β€”  app1.jpg
    ο½œβ€”β€”2_st_app2.py  # st_app2 needs the files from fold app1
    ο½œβ€”β€” app2  # this is a folder
       ο½œβ€”β€”  app2.py   
       ο½œβ€”β€”  app2.json
       ο½œβ€”β€”  app2.jpg
    ο½œβ€”β€”3_st_app3.py
β€”β€” requirements.txt

I try on local and streamlit cloud, they do not work,
st_app1.py need import app1.py from app1, but an error of import app1.py occurs

How are you doing your imports? Imports should be relative to the main file of your app.

1_st_app1.py as a script in pages would need to import from pages.app1.app1 for example and you may need to make sure you have an __init__.py file (can be empty) sitting in pages/app1.

Thanks, I solve it by add the file path, in 1_st_app1.py and 2_st_app2.py

import sys
import os

current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)

My finnal coding of 1_st_app1.py like this

import sys
import os

current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)

# my former wrong  coding :from app1 import app1

from pages.app1 import app1 
print('get app1.py success')

And I didnt add init.py, it still works

Before, I am not familiar with absolute path and relative path, so I got confused, Now I solve it and learn, thank you for your help @mathcatsand

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.