Skip to content

munich-ml/streamlit_db_browser

Repository files navigation

Database browser app

This web-app allows browsing and exploring data from InfluxDB database. It is realised using Streamlit and runs from Docker on a Raspberry pi. Example query:

ToDos

  • resample doesn't work as intended: 24h resample is not per day (example Mini Milage)
  • filter transformer would be great

Moving docker to the Raspi

Prerequisite: Install Docker on the Raspi acc. to: Docker installation on Debian

  1. Update source from within the cloned project directory (e.g. ~/Desktop/streamlit_db_browser):

    $ git pull
    
  2. Build the docker image and tag it with streamlit-db-browser:

    $ sudo docker build -t streamlit-db-browser .
    
  3. Run the streamlit-db-browser image as a container and expose the port 8501

    $ sudo docker run --rm -p 8501:8501 streamlit-db-browser
    

Afterwards, the app is available at http://192.168.XXX.XXX:8501/.

On the Raspi, containers an images can be inspected using docker commands such as:

$ sudo docker ps
CONTAINER ID   IMAGE                  COMMAND                  STATUS                    PORTS                    NAMES
7b3ad304804f   streamlit-db-browser   "streamlit run strea…"   Up 32 minutes (healthy)   0.0.0.0:8501->8501/tcp   lucid_dijkstra
...

$ sudo docker images
REPOSITORY             TAG       IMAGE ID       CREATED          SIZE
streamlit-db-browser   latest    bbc83ac40de9   34 minutes ago   984MB
...

Appendix: My Docker journey

Notebook of my first contact with Docker

Docker steps: build and run

  1. docker build -t IMAGE_TAG_NAME . creates a docker image from the Dockerfile.
  2. docker run IMAGE_TAG_NAME runs the an instance of the docker image, called a docker container.

I used this modified version of the Dockerfile from the Streamlit Docker tutorial - each line of the Dockerfile is described in the tutorial.

# app/Dockerfile

FROM python:3.9-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    git \
    && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/munich-ml/streamlit_db_browser.git . 

RUN pip3 install -r requirements.txt

EXPOSE 8501

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

ENTRYPOINT ["streamlit", "run", "simple_app.py", "--server.port=8501", "--server.address=0.0.0.0"]

Problem updating docker build

When rebuilding a docker image from the same Dockerfile (e.g. because the .git source was updated) the following error occured:

ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y     build-essential     curl     software-properties-common     git     && rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100

Workaround: Duplicate the Dockerfile and delete the original one. Funny enough, that works.

Accessing the app from other devices in the same network

Assuming the container is started on a PC with the local IP 192.168.178.50 using this command:

docker run --rm -p 8765:8501 my_simple_app

then the application within the docker image my_simple_app can be accessed from other devices on the same network at:

http://192.168.178.50:8765/

The external port 8765 is mapped to 8501 within the container (see Dockerfile).

Franky1's streamlit-template

Maybe worth trying: https://github.com/Franky1/Streamlit-Template/

Putting the Dockerfile into the Github repo

The Streamlit Docker tutorial I used above clones the source using RUN git clone from within the Dockerfile. Now that I put the Dockerfile into my repo, I replaced that by COPY . .:

# RUN git clone https://github.com/munich-ml/streamlit_db_browser.git . 
COPY . .

About

Streamlit web-app for browsing an InfluxDB database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published