Streamlit Development & Running Offline

Streamlit provides an easy and rapid way to turn data scripts into interactive web apps. However, at times, developers may need to ensure that their Streamlit applications run offline. Here’s a simple guide to setting up Streamlit in an offline environment using Anaconda and Visual Studio Code (VSCode).

Setup with Anaconda Environment

Follow these steps to set up Streamlit within an Anaconda environment:

  1. Install Anaconda & VSCode

  2. Create a Python Conda Environment

    conda create --name bds-streamlit python==3.11.4
    
  3. Activate the Environment

    conda activate bds-streamlit
    
  4. Install pipreqs

    • pipreqs is a handy tool that scans through your project files, detects the Python imports, and subsequently generates a requirements.txt file.
    pip install pipreqs
    
  5. Generate requirements.txt

    pipreqs
    
  6. Install the Necessary Packages

    pip install -r requirements.txt
    

Alternative Setup without Anaconda Environment

If you’d rather not use a specific environment:

  1. Install Anaconda & VSCode (as mentioned above).

  2. Install the Required Packages Directly

    pip install pandas streamlit matplotlib altair seaborn
    

Running the Streamlit App

  1. Navigate to Your Project Directory

    cd path/to/your/app_directory
    
  2. Run the App

    streamlit run app.py
    
    • Alternatively (especially for Windows users), you can execute:
    python -m streamlit run app.py
    

With these steps, you’re all set to develop and run your Streamlit apps offline! Whether you’re using an Anaconda environment or not, the process is straightforward and ensures you have all the necessary dependencies installed.