How to most easily share your streamlit app locally?

@andreas_rc do you have any leads about heavy tweaking steps to settings? Iā€™m happy to try from my end and debug

Yes, thatā€™s how it worked. Since we had a common shared folder we did not need to have the ability to upload your own files.

Unfortunately nothing specific. I had several error messages and was able to get past some of them with google but in the end stopped. Iā€™ll check out Docker + AWS to share. If you have success with .exe would be interested to see!

Nice! I tested it and it does seem to work well. However, I get a 405 error when trying to use the st.file_uploader.

I also tried to select a path as follows:

# load data
path_input_data = st.sidebar.text_input("Provide the name to the subfolder in which your csv files are "
                                            "stored.")
if path_input_data:
    excel_files = glob.glob(path_input_data + '/**/*.csv', recursive=True)
    st.write(excel_files)

What I want to do is provide the complete path to the local folder in which data is stored. When creating a container I can only refer to the relative path inside of the container, which means that users cannot select their own data. Any suggestions on how to work around this? Iā€™m probably missing something obvious here, as I am not too familiar with Docker images.

We also continue to keep in touch over email, but just to keep any other readers up to date, here is a summary of our discussion:

Thank you for getting in touch - Iā€™m really pleased to hear you have enjoyed ContainDS Desktop!

I think the important piece of information you are missing is that the ā€˜workspace folderā€™ on your computer maps to the path ā€˜/appā€™ inside the Docker container.

So for example, on my Mac the container is running with a workspace of /Users/dan/streamlit-single and this can be accessed via /app in the containerā€™s Streamlit code.

Here is my example folder on the Mac:

|- code.py
|- csvfiles
     |- test.csv
     |- testboxes.csv

My version of the Python code is at the end of this email, showing two methods of accessing the files - direct access through Python code, and then using st.file_uploader.

For the direct access method (not using st.file_uploader) it is important to understand that most of your computerā€™s hard drive is not accessible directly by the container. That is essential for security. So the csv files should ideally be in your workspace folder (as mine are above). You could always use a symlink if you really wanted to store them elsewhere on your hard drive.

Rather than expect the user to know that /app is the location for accessing the workspace from inside the container, in my example code I just expect them to type the immediate subfolder name of ā€˜csvfilesā€™ and then I prepend ā€˜/app/ā€™ to that. In fact, if you just want to find all csv files in the workspace then you could just glob from the /app folder recursively anyway, so you donā€™t really need to specify the subfolder name.

For the file uploader version, Iā€™m not too sure why you were seeing the 405 error. It seems to work for me using the streamlit-single Docker image, but I do see the 405 error using streamlit-launchpad images. Iā€™ll take a look.

ā€“

import streamlit as st
import glob
from os import path
import pandas as pd

st.markdown('# Based on subfolder path')

path_input_data = st.sidebar.text_input("Provide the name to the subfolder in which your csv files are "
                                            "stored.")

st.write("Input path:", path_input_data)

docker_search_path = path.join('/app', path_input_data)

st.write("Search path:", docker_search_path)

if path_input_data:
    excel_files = glob.glob(docker_search_path + '/**/*.csv', recursive=True)
    st.write(excel_files)

st.markdown('# Now try uploading')

uploaded_file = st.file_uploader("Choose a CSV file", type="csv")

if uploaded_file is not None:

     st.write('Uploaded file: ', uploaded_file)
     data = pd.read_csv(uploaded_file)
     st.write(data)

st.write('Streamlit version: ', st.version._get_installed_streamlit_version())
1 Like

Iā€™ve updated streamlit-launchpad to work with the file_uploader now (version 0.0.6). To pick this up you might need to restart ContainDS Desktop and then create a new container from the latest ā€˜streamlit-launchpadā€™ in the Images tab.

@ bjornvandijkman
I have successfully created the .exe file by your procedure. But unable to run the .exe file, Itā€™s throwing the below error.
ā€˜Failed to execute script run_streamlitā€™
Please help!!

# st-run-test.py
import streamlit as st
def main():
    """    # do stuff here. """
    st.markdown("Test this and that")

if __name__ == "__main__":
    main()

# run-st-test.py
import subprocess as sp
import shlex

sp.call(shlex.split("streamlit run st-test.py"), shell=True)

I seem to successfully freeze run-st-test.py with pyinstaller (pyinstaller run-st-test.py -c) and run the exe. Will give it a try with my rather complicated streamlit project. I would guess it should work.

It also works with more complicated cases. The problem is, it only freeze run-st-test.py.

I am looking for a way to freeze st-run-test.py and anything it makes use of. The reason: I want other people to be able to run my streamlit program without explicitly sharing the source code. Is this possible?

@mikee @bjornvandijkman
This is not the solution I was hoping for, as it only makes an .exe file of the calling script. Python and streamlit still needs to be present on the executerā€™s computer.
Thatā€™s why Srinath and andreas are not able to run the .exe
Am I missing something or is it just not possible to create a (single) executable with pyinstaller for streamlit apps?

I have not used pyinstaller since to be honest. I have however successfully shared applications locally using containds of @danlester.

2 Likes

Hi Chekos,

That is actually a really brilliant solution that I could use for many challenges, not just streamlit.
Installing python or anaconda to a shared drive is easy enough. But what I do not get, is how you managed to install the extra libraries to the shared drive?

I have python on my own machine and on the shared drive now, but pip installing will just install them on my own machine. How did you get around this?

1 Like

Hi all -

Iā€™m new to Streamlit AND not familiar with deploying apps. I have started creating a Streamlit app and want to be sure I can deploy this locally before continuing to work on it.
This thread has become quite long and I donā€™t believe I see anywhere people have been able to do this without using some other resource. The requirements I have seem to match with those stated in the initial question here.

  1. What I think I understand from the latest posts is installing python and streamlit, and other necessary libraries for the specific app (on the shared drive), makes this possible. Does that sound correct?

  2. If number 1 here does work, I still need direction on what to do and what exactly I can provide to my non-techy co-workers. Can anyone help with that?

If it helps hereā€™s what Iā€™m doing - the simple app I am creating reads in pickle files stored locally and shows some data to the user. It then gets input from the user that is then stored back in the pickle files. This app doesnā€™t involve a machine learning model. Itā€™s very simple. Iā€™d like the user to be able to go their browser and open a link to access this OR click on a short-cut on their screen. Currently, this is set up for Windows users but I can revise the code to open the file location for mac users later. I donā€™t want to work on the app further until I know I can deploy what I have without the cost of subscribing to a service.

Thank you.

More questions regarding my last ones.

  1. Can I deploy something locally that points to data on our local drives?
  2. How do I deal with allowing only one user access at a time?
  3. I canā€™t access the link provided for ContainDS.

Update: Iā€™ve installed PyInstaller to test making an executable with it. Itā€™s in the process of creating it now. The down-side is it seems to be taking into consideration every possible package, that shouldnā€™t necessarily be in my environment, not only the couple packages I would list in a requirements.txt file.

To be clear, is your goal to create an executable for each person to be able to run the app (conveniently) on their own computer, with the app then having access to that userā€™s local files? Or are you talking about everyone being able to access the app through your local network by having it run on a network computer on which the files are stored?

The latter is much simpler. When you install Python and install streamlit on some host computer, and then you streamlit run your_app.py on that computer, the app becomes available to all computers on your local network (modulo firewall settings). As long your computer and network firewalls arenā€™t locked down tight, then all the computers that can ā€œseeā€ the host machine will be able to access the app through that host machineā€™s ip address. If your app useā€™s a file_uploader widget, then users will be able to select files from their own machines to send to the app. But if the app is using some files specified by a path within the code, it would be trying to find those files on the host machine.

Thank you @mathcatsand.

Iā€™d like each person to be able to run the app on their own computer - however that may be. They would be accessing the same files on the shared network drive.

Iā€™m thinking if they have are logged onto their computer and already accessing the network drives they shouldnā€™t have a problem with any network firewalls or be locked out. Iā€™m not using the file_uploader widget. The code is loading the files based on the location on the network drive.

The .exe file made by PyInstaller works. Iā€™m going to look at the subprocess mentioned above so the user doesnā€™t have to take the second step of opening the command prompt to enter streamlit run your_app.py

Added the code for the subprocess as shown above, like this:

# run-st-test.py
import subprocess as sp
import shlex

sp.call(shlex.split("streamlit run st-test.py"), shell=True)

The problem I have with this is if I run the code, it ends up in a loop. It keeps running the subprocess. I will read more about subprocesses.

That is expected, web apps are expected to run forever (until an error happens or somebody else kill them).

Thanks @Goyo, I understand that. I was looking for thoughts on how to get around this.

I set this piece aside for the moment but my thought is to figure out how to get this piece to run only once. Iā€™m thinking I might be able to do this using a session state.

Note that this is unrelated to your use of subprocess. It would be the same if you run streamlit from a console or a batch script.