Skip to content

Commit

Permalink
Cleanup, tweak main screen and added About page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mjboothaus committed May 15, 2023
1 parent 5445603 commit 2210b90
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 16 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://stackoverflow.com/questions/68673221/warning-running-pip-as-the-root-user
# for enhancements to Dockerfile e.g. not running as root & in venv

FROM python:3.11-slim-bullseye
RUN apt-get update && apt-get install -y

EXPOSE 8080

RUN pip install -U pip

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# Copy into a directory of its own (so it isn't in the toplevel dir)

COPY .streamlit app/.streamlit
COPY data app/data
COPY docs app/docs
COPY src app/src

WORKDIR /app

# Run it!

ENTRYPOINT ["streamlit", "run", "src/Emmaus_Walking.py", "--server.port=8080", "--server.address=0.0.0.0"]
3 changes: 3 additions & 0 deletions README_pdm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pdm update

pdm export --o requirements.txt --without-hashes
2 changes: 1 addition & 1 deletion app_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DATASOURCE = 'Apple Watch via Health Fit'
AUTHOR = 'by [DataBooth.com.au](https://www.databooth.com.au)'
NAME = 'Emmaus Walking Mapping App'
CACHED_DATAFILE = 'emmaus_walking.cache.feather'
CACHED_DATAFILE = 'data/emmaus_walking.cache.feather'
LAYOUT = 'wide'

[S3] # Cloud Object Storage: https://console.scaleway.com
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Emmaus Walking App

Simple [streamlit.io](https://www.streamlit.io) web app to display some of the major walking trails that I have done.

Data has been captured on a number of Apple Watches.


Developed by [DataBooth](https://www.databooth.com.au).
12 changes: 11 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies = [
"streamlit-folium>=0.11.1",
"folium>=0.14.0",
"Pillow>=9.5.0",
"tomli>=2.0.1",
]
requires-python = ">=3.10"
license = {text = "DataBooth"}
Expand Down
117 changes: 117 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# This file is @generated by PDM.
# Please do not edit it manually.

altair==4.2.2
anyio==3.6.2
appnope==0.1.3
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
attrs==23.1.0
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
blinker==1.6.2
branca==0.6.0
cachetools==5.3.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
comm==0.1.3
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.2.0
fastjsonschema==2.16.3
folium==0.14.0
fqdn==1.5.1
gitdb==4.0.10
gitpython==3.1.31
idna==3.4
importlib-metadata==6.6.0
ipykernel==6.23.0
ipython==8.13.2
ipython-genutils==0.2.0
isoduration==20.11.0
jedi==0.18.2
jinja2==3.1.2
jsonpointer==2.3
jsonschema==4.17.3
jupyter-client==8.2.0
jupyter-core==5.3.0
jupyter-events==0.6.3
jupyter-server==2.5.0
jupyter-server-terminals==0.4.4
jupyterlab-pygments==0.2.2
markdown-it-py==2.2.0
MarkupSafe==2.1.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mistune==2.0.5
nbclassic==1.0.0
nbclient==0.7.4
nbconvert==7.4.0
nbformat==5.8.0
nest-asyncio==1.5.6
notebook==6.5.4
notebook-shim==0.2.3
numpy==1.24.3
packaging==23.1
pandas==2.0.1
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.5.1
prometheus-client==0.16.0
prompt-toolkit==3.0.38
protobuf==3.20.3
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pyarrow==12.0.0
pycparser==2.21
pydeck==0.8.1b0
pygments==2.15.1
pympler==1.0.1
pyrsistent==0.19.3
python-dateutil==2.8.2
python-json-logger==2.0.7
pytz==2023.3
pyyaml==6.0
pyzmq==25.0.2
requests==2.30.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.3.5
Send2Trash==1.8.2
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
soupsieve==2.4.1
stack-data==0.6.2
streamlit==1.22.0
streamlit-folium==0.11.1
tenacity==8.2.2
terminado==0.17.1
tinycss2==1.2.1
toml==0.10.2
toolz==0.12.0
tornado==6.3.2
traitlets==5.9.0
typing-extensions==4.5.0
tzdata==2023.3
tzlocal==5.0
uri-template==1.2.0
urllib3==2.0.2
validators==0.20.0
watchdog==3.0.0
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.1
zipp==3.15.0
48 changes: 34 additions & 14 deletions src/app.py → src/Emmaus_Walking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import folium
from PIL import Image

# from datapipe import load_and_cache_raw_walk_data, calc_walk_stats
# from datapipe import load_and_cache_raw_walk_data, calc_walk_stats - no longer needed

DATA_INFO = "Apple Watch via Health Fit"
AUTHOR_INFO = "by [DataBooth.com.au](https://www.databooth.com.au)"
APP_NAME = "Emmaus Walking Mapping App"
CACHED_WALK_DATA = "emmaus_walking.cache.feather"
APP_TITLE = "Emmaus Walking Mapping App"
CACHED_WALK_DATA = "data/emmaus_walking.cache.feather"
IMAGE_PATH = "src/resources"
IMAGE_PATH = Path.cwd().resolve() / IMAGE_PATH

Expand All @@ -30,14 +30,36 @@
WALK_NAME += ["ALL: All Walks"]


st.set_page_config(page_title=APP_NAME, layout="wide")
# Note this must be the first function call in the Streamlit app code

st.set_page_config(
page_title=APP_TITLE,
page_icon="🚶",
layout="wide",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'https://www.databooth.com.au/help',
'Report a bug': "https://www.databooth.com.au/bug",
"About": "Created with love & care at DataBooth - www.databooth.com.au"
},
)

# config = read_toml_file()
# SUB_TITLE = config["st-app"]["SUB_TITLE"]

def create_app_header(app_title, subtitle=None):
st.header(app_title)
if subtitle is not None:
st.subheader(subtitle)
return None


# create_app_header(APP_TITLE)


class SideBar:
datasource = DATA_INFO
datasize = 0 # look to calculate this (in MB?) - TEST: Comment change
author = AUTHOR_INFO
data_title = "Data details..."
data_local = False
start_date = dt.date.today()
end_date = dt.date.today()
Expand Down Expand Up @@ -66,9 +88,8 @@ def plot_walk_points(walk_points, map_handle, linecolour, linewidth):
folium.PolyLine(walk_points, color=linecolour, weight=linewidth).add_to(map_handle)


def app_sidebar(APP_NAME):
def app_sidebar():
sb = SideBar()
st.sidebar.info(APP_NAME)
col1, col2 = st.sidebar.columns(2)
with col1:
image1 = Image.open(IMAGE_PATH / "AppleWatchExercise.jpeg").resize(
Expand All @@ -78,7 +99,7 @@ def app_sidebar(APP_NAME):
with col2:
image2 = Image.open(IMAGE_PATH / "HealthFitLogo.png")
st.image(image=image2, use_column_width=True, output_format="PNG")
st.sidebar.markdown(sb.author)
# st.sidebar.markdown(sb.author)
# st.sidebar.markdown(sb.datasource)
# st.sidebar.info(sb.data_title)
# st.sidebar.markdown('Datasize: ' + str(sb.datasize))
Expand All @@ -100,9 +121,8 @@ def load_cached_walking_data():
return pd.read_feather(CACHED_WALK_DATA)


def app_mainscreen(APP_NAME, sb):
# st.title(APP_NAME)
st.header(sb.walk_name)
def app_mainscreen(APP_TITLE, sb):
st.subheader(sb.walk_name)

# Load walking data
# OLD_WAY ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,5 +187,5 @@ def app_mainscreen(APP_NAME, sb):
# return map_handle, walk_data, walk_date, walk_points


sb = app_sidebar(APP_NAME)
map_handle = app_mainscreen(APP_NAME, sb)
sb = app_sidebar()
map_handle = app_mainscreen(APP_TITLE, sb)
38 changes: 38 additions & 0 deletions src/helper_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import tomli as tomllib
from IPython.display import Markdown, display
from streamlit import cache_data, markdown


@cache_data
def st_read_markdown_file(markdown_file):
return Path(markdown_file).read_text()


def read_markdown_file(markdown_file):
return Path(markdown_file).read_text()


def read_render_markdown_file(markdown_file, output="jupyter"):
if output == "jupyter":
try:
md_text = read_markdown_file(markdown_file)
display(Markdown(md_text))
except Exception:
print(f"Error with markdown file: {markdown_file}")
return None
else:
try:
md_text = st_read_markdown_file(markdown_file)
markdown(md_text, unsafe_allow_html=True)
except Exception:
print(f"Error with markdown file: {markdown_file}")
return None


@cache_data
def read_toml_file(toml_file="./src/app_config.toml"):
with open(toml_file, "rb") as f:
toml = tomllib.load(f)
return toml
3 changes: 3 additions & 0 deletions src/pages/1_About.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from helper_functions import read_render_markdown_file

read_render_markdown_file("docs/about.md", "streamlit")

0 comments on commit 2210b90

Please sign in to comment.