Streamlit or Dash (or Shiny for Python?!)

Published

July 31, 2022

I virtually attended part of the Rstudio conference, more specifically I watched a few streams and also participated a bit on their neat conference Discord server.

While I am almost exclusively a python user these days, I started with R. I took my first baby steps towards becoming a data scientist in R using swirl and used R for my Data Incubator application questions. My final project there involved a Shiny application, and the first version of my covid dashboard was in Shiny. However, having not used R in a long time, I learned a lot of new things just looking at the Discord channels before the conference even started.

New thing 1: Streamlit

Quick and easy to write an app

Ironically, the first new thing (to me) that I read about was streamlit, which is a python web framework. Like Dash, it’s designed for quick python web data apps. It is definitely less flexible/extensive as Dash. I could not recreate anything like Recorded Vote with it. However, for simple apps with relatively simple data structures it is much faster/easier than Dash. I put together a streamlit front end for my covid case dashboard very quickly, and with a lot less code.

Can be a bit slow…

The biggest downside of streamlit is the way the entire script runs every time any interaction occurs. For something like my covid dashboard, this isn’t a very big deal as all the data now lives in a fairly fast SQLite database so there are no expensive functions generating data. At work, however, when I tried to put together a streamlit app, re-running the script meant re-initializing our somewhat complex work environment every time, making it slower than its Dash counterparts I had already written. And complex objects couldn’t be cached. (I still need to try their experimental memoization). Still, for simpler apps the speed and ease of writing up streamlit without having to think of callbacks is very appealing.

Not so easy to deploy (for me.)

The problem, for my personal use, came when I looked into deploying a streamlit app. The framework relies on and integrates with the tornado web server. I can’t just add a streamlit app to my uwsgi setup, which would have been ideal.

The reliance on tornado also mean more memory usage, and running on my small web host, not being able to share memory efficiently the way uwsgi allows kind of makes this a deal breaker. Between the app and pipenv, I’d say the streamlit version of my covid dashboard uses 220MB of RAM. The dash version in uwsgi uses maybe 94MB - and if a second thread dynamically spins up it doesn’t double the memory usage.

So, I won’t be deploying any streamlit apps myself to my own web site any time soon, but pretty handy for just quickly putting together an interface for use locally. Update I deployed a version of my covid dashboard to streamlit cloud, and to keep the data live I wrote a REST API that serves up the data from the sqlite database on my own server.

Second New thing: Quarto

I liked Quarto so much I have already rewritten my post on the most popular Wordle openers in it. (Both on this site and on quarto.pub just to test the publishing feature.) Since moving to mostly python, I have really missed Rmarkdown. I appreciate that quarto is language-agnostic, can render notebooks, and properly preserves my interactive plotly graphs when making HTML documents. And there’s a VS Code plugin!

Most surprising thing - Shiny for Python?!

Yes, shiny, which had far and away been my favorite thing about R now exists for python, albeit in a very early alpha state.

It turns out, I have made maybe one actually Shiny app - I usually made Shiny Rmarkdown documents, so laying out a UI for Shiny isn’t my strong suit. Thus, I haven’t played around with this much yet. It also only supports matplotlib for plotting so far. A regular Shiny server can serve up Shiny Python apps, but other deployment options are harder. I’ll have to see how this develops.

The R data community is fun

This was actually my biggest takeaway from the conference. I feel like, if there is a Python data science community, we’re not nearly as fun or cohesive as the R crowd. Nor do we gather at any one conference. (Pandasconf?!)

Python is used for all kinds of things, so python users have all kinds of interests. R people by definition are almost all doing stats or science or something interesting with data. I may not actually use R that much anymore, but I definitely wanted to be friends with all of the Rstudio conference people.