streamlit-demo
Streamlit application powered by a PyScaffold project setup.
Work in progress: The idea of this repo is to demonstrate how to package a streamlit app using PyScaffold. Since streamlit currently doesn't support apps as proper Python packages, this example is still suboptimal. Following Github issue was created to improve the current situation.
The structure was created with:
putup --dsproject streamlit-demo -p git_overview \
-d "Streamlit application powered by a PyScaffold project setup." \
-u https://github.com/pyscaffold/streamlit-demo
then the actual code was taken from git-overview (MIT-licensed) and changed into a proper Python package layout.
The advantages over the original codebase are:
- wheel file for distribution can be easily build with
tox -e build
, - unit tests can be easily added in the
tests
folder, extract-repo
is now a shell command (available after installation) instead of a scriptrepo.py
,git_overview
is a Python package that could be reused by other Python projects after installation,- all the other advantages of a PyScaffold layout...
Installation & Running the dashboard
In order to set up the necessary environment:
- create and activate the environment
streamlit-demo
with the help of conda:conda env create -f environment.yml conda activate streamlit-demo
environment.lock.yml
to recreate an environment with pinned dependencies.
NOTE: The conda environment will have streamlit-demo installed in editable mode. Some changes, e.g. in
setup.cfg
, might require you to runpip install -e .
again.
-
run the dashboard with:
streamlit run scripts/show_dashboard.py
-
or (optionally) build a docker image and run it with:
docker build -t local/streamlit-demo:latest . docker run -p 8501:8501 local/streamlit-demo:latest
-
open the dashboard at http://localhost:8501.
Project Organization
βββ AUTHORS.md <- List of developers and maintainers.
βββ CHANGELOG.md <- Changelog to keep track of new features and fixes.
βββ CONTRIBUTING.md <- Guidelines for contributing to this project.
βββ Dockerfile <- Build a docker container with `docker build .`.
βββ LICENSE.txt <- License as chosen on the command-line.
βββ README.md <- The top-level README for developers.
βββ docs <- Directory for Sphinx documentation in rst or md.
βββ environment.yml <- The conda environment file for reproducibility.
βββ pyproject.toml <- Build configuration. Don't change! Use `pip install -e .`
β to install for development or to build `tox -e build`.
βββ scripts <- Entry-script `show_dashboard.py` for streamlit
βββ setup.cfg <- Declarative configuration of your project.
βββ setup.py <- [DEPRECATED] obsolete way of building and installation.
βββ src
β βββ git_overview <- Actual Python package `git-overview` with the main functionality.
β βββ __init__.py
β βββ dashboard.py <- Layout-function of the actual dashboard.
β βββ repo.py <- Functions to download repo data.
β βββ utils.py <- Some dashboard-related helpers
βββ tests <- Unit tests which can be run with `pytest`.
βββ .coveragerc <- Configuration for coverage reports of unit tests.
βββ .isort.cfg <- Configuration for git hook that sorts imports.
βββ .pre-commit-config.yaml <- Configuration of pre-commit git hooks.
This structure is in strong contrast to the original one:
βββ app
β βββ dashboard.py <- Dashboard entry-point
β βββ __init__.py
β βββ repo.py <- Script to download repo data
β βββ utils.py <- Some dashboard-related helpers
βββ Dockerfile
βββ README.md
βββ requirements.txt
Note
This project has been set up using PyScaffold 4.1.1.post1.dev28+g075b76f and the dsproject extension 0.6.1.post28+g91ab61a.