Compatibility problem between local Stremlit and Cloud

My streamlit app is located in a folder of my repository (streamlit_app).

My data are also located in a folder (data) at the same level than “streamlit_app”.
My local app is running well…
When I want to upload it in the cloud, I define the repository, the branch, the Main file path (streamlit_app/, and the url.
The problem is that the app does find my assets files (images files in the folder “assets”), or the file style.css located in the folder “streamlit_app”.
To make a long story short, it seems that the app on the cloud considers that the default path is not “streamlit_app”.
How can I set this path , so the same program run as well locally and in the cloud ?
Thank you

It’s generally a good practice to keep the (main streamlit app) at the root of the repository instead of putting inside a folder, unlike other pages/tabs and data… etc, e.g:

GitHub repo root
    ├── > data
    │   └── # your data
    ├── > assets
    │   └── # assets and styling files
    ├── > tabs
    │   └── # your different streamlit pages
    ├── .gitignore
    ├── requirements.txt

Thank you for your response, but I have no choice.
Is there a way to solve the issue ?

I can’t try things out right now but I suggest you try my previous solution jsut to see the app actually deploys fine with that files setup. You can deploy a test branch in which you have the at root (I reckon you’ll have to relink your data for this testing).

Or try this (from the top of my head) have a at root of the folder, in which it calls the from streamlit_app/ and run the streamlit main function. This could work, try it out from a separate branch as well and let me know your results on both suggested solutions.

Indeed, in Streamlit Cloud the current path is the root of your repository.

You can use os.chdir.

Thank you IndigoWizard,
but can you help me in what I should write in to call ?

@Olivier_Renouard Sure, do you have a link to your GitHub repo I might push a Pull Request or if it’s private I’ll have to build and deploy a demo app or just quick code sample indications, you pick.

Thank you Goyo, that works, and that was easy to implement:
Here is the code I added in the file in order to run both locally and in the cloud.

‘# Define the root folders depending on local/cloud run
thisfile = os.path.abspath(file)
if (’/’ in thisfile): os.chdir(os.path.dirname(thisfile))

Cool to see that Goyo’s method worked for you @Olivier_Renouard

I had already setup a repo for a demo app and depoyed it for testing x)
Anyway, here’s one other method to get it done if anyone is interested:

Thank you very much for your help IndigoWizard.
Your solution is more elegant as you don’t need to modify the code.
I will test it later.
Again thank you

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