As someone who taught himself BASIC in the 1980s and was taught Fortran 77 in the early 1990s*, I do need to try and keep up with modern developments. One of the things I have being wanting to for a while now, is find a way of putting some simple plotting/data analysis on the web, so anyone can use it. There have been solutions for this problem for a while but until yesterday I had not come across one I liked. I want to go from Python code on my local machine to a running a web app in minutes, and I want to spend a couple of hours learning how to do this at a very basic level. I am kind of busy so can’t spend a day learning this. I think I have a solution that fits these criteria, and I am pretty pleased with it.

It has two parts: Streamlit, and Heroku. Streamlit is designed to be a fast way of creating simple interactive apps, for example interactive plots, using Python. So the emphasis is on getting an interactive plot or similar up and running in web browser tab, in minutes, rather than flexibility or the ability to fine tune details. It runs on your local machine, and is great at doing simple sliders which allow you to adjust the value of parameter; it then replots the function with the new value automatically. It is easy to learn how to do a simple plot or animation by just copying and editing a working code.

The second part is Heroku, which hosts light duty apps for free and has very simple procedures for uploading your code. It uses git which I generally don’t like but here that is straightforward and worked more-or-less first time for me, which given how bad I am at anything git-related is a miracle. Drew Hibbard has a nice step-by-step guide to getting your code to produce the app, aka deploying your app. My app was working within about an hour of getting my Heroku account, which I think is pretty good**.

My first app is an interactive plot of the Well-Riley model for the transmission of respiratory diseases, as applied to transmission of COVID-19. See here for the app. If you run it on the evening I wrote this blog you should see it is rough but works. You can produce plots of the Wells-Riley prediction of the probability you will become infected, as a function for the length of time you spend in the same room as one infected person. With handy sliders you can see the effects of room ventilation, how infectious the infected person is, and so on.

If you are reading this later than that, I may have improved it a bit. Either way, comments are open below if you have any feedback, suggestions for improvement. It is pretty simple but even so I think it is useful to able to see essentially instantly the effect of, for example, increasing ventilation, on the predicted chance that you will become infected. Final point: As I note in earlier blog posts (here and here), the Wells-Riley model is very highly simplified and so more of a simple guess at infection probabilities than a model you should rely on.

* Due to my immense age and as I do a lot of computing teaching, occasionally a student who for a research project needs to do Fortran 77 code, asks me some questions about it. I am happy to help, and it cracks me up that they talk about Fortran 77 a bit like I talk about the Dead Sea Scrolls.

** I also tried Microsoft Azure, which can also run web apps running Streamlit. That was a mistake. Azure’s panels are stupidly complex for what I wanted to do.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s