Root directory for streamlit

What is the local root directory used by streamlit? If I want to host local media, is there a directory I can put the files in?

Dinesh

The root directory seems to be where the streamlit main file is. It doesn’t seem to be looking at the environment variable PYTHONPATH which was strange to me. It means that in order to import modules from your project, you have to put the streamlit main script in the root of your project regardless of the PYTHONPATH. That goes for local media as well, everything starts from the folder where the main script is.

Thanks @Alon. I didn’t ask my question well. I knew the info you’re saying.

However, if I use “img src=a.jpg” from a local directory, I cannot make a.jpg image displayed. The web server seems to be looking for the image in a different place. Thats the location I’m looking for.

Dinesh

Why not use st.image('a.jpg') if the file is in the current root folder?

Various reasons related to how I want to place the image and text adjacent to it. @ash2shukla gave me a nice solution as the one recommended using native streamlit such as using st.beta_columns() didn’t work well for me. While @ash2shukla’s solution fixed the problem for me, I’m still curious to find the answer to what is the root directory for the webserver streamlit uses.

Best wishes,

Dinesh

Hey @ddutt,

The images are not hosted as it is, they are transformed and then hosted. So you can never actually get the original file over a static serve I think. The file directory where images are picked from is the same as your streamlit script directory but the name is changed to a sha224 hash of transformed content. Refer these to understand more,
The url would look something like this,

http://localhost:8501/media/de398b1efa63fc9f2d174278cf9e796c9a25fe03e8e1d4a5577c5dd9.jpeg

Hope it helps !

Maybe someone from streamlit devs can correct me if I am wrong @tim ?

1 Like

Very cool, thanks once again @ash2shukla.

So it looks like your trick of using the base64 and the markdown is the best approach. I think that is worthy of a FAQ entry. Don’t you?

Best wishes,

Dinesh