A Python web app in under an hour
Posted on Mon 13 January 2025 in FOSS
As I was packing up on Friday, I received an email from a old scientific collaborator Dr. D. asking for advice on how to share some scientific data on the internet. He wanted to share the real time status of some automatic weather stations (AWS, not the Bezos one) and some timeseries of temperature humidity etc. My interest was sufficiently piqued that ,when I got home1, I gave myself an hour to knock together the best solution I could. It resulted in this:
https://aws-demo.streamlit.app/
Source code: https://github.com/callumrollo/streamlit-demo-aws
Requirements/Motivation
As communicated by Dr. D., the web app needed to:
- Show near real time uptime stas and science time-series data
- Be easy to implement and maintain
- Be python based
Some additional requests were:
- To run locally on-site where the weather station is
- Be interactive (zoom/pan data)
I had been meaning to try out streamlit for a while now. While my usual go-to is to whip up a python-flask app for all my website and slippy map purposes (for more see this post), this request called for something much simpler and more user-friendly to create.
Steps
- Search the internet for "streamlit"
- Copy and paste their quickstart
pip install streamlit && streamlit hello
2 - Realise I actually wanted more of a chart
- Read the Docs (yuck)
- Copy and paste an example with a chart I wanted
- Run that locally with
streamlit run app.py
- Make some fake data in a pandas dataframe
- Edit the example to show the two basic charts I wanted
- Add some download functionality
- Publish the app to github
- Deploy the app to streamlit community
- Add instructions
- Present this to Dr. D.
- Write this blog post in case others may benefit!
Steps 1 - 12 took just under an hour. I chatted with Dr. D. for 30 minutes about the solution (he was very happy!) and took another 30 to write this blog post. It's rough and ready but does the job.
Reflection
When I talk to friends in tech, they are often surprised/alarmed by the outdated tech stack and approaches that scientists use to do our work. Public perception is that we're at the cutting edge, most people would be shocked to see how old-school and just plain old a lot of the tools we depend on are. While I personally think novelty is overrated (climate models are fine in FORTRAN, please stop suggesting we rewrite X in rust) a lot of science, particularly on the data-viz/public outreach front, could be much better if it used modern, dynamic tooling.
It's brings me a lot of joy to help colleagues with things like this. If there is any through line to my career and personal ethos, it is creating/improving/teaching tooling that makes other scientists more effective. Some of my proudest moments during my PhD were spending a few hours writing bash scripts that saved my fellow students weeks of manual work.
Footnotes
- I listened to Deafheaven - Ordinary Corrupt Human Loveand Charli XCX- Crash while writing this post