Streamlit review and demo: best of the Python data app tools
This article was originally published in January 2021. It has been updated to reflect recent Streamlit company news, new features, and a new demo app of our own. One thing that has not changed is that The Crosstab Kite does not accept compensation of any kind from vendors, so our reviews are as unbiased as possible.
Streamlit launched in 2018 to help data scientists build data apps, emphasizing fast development with a pure Python approach. Our hands-on testing showed that it’s the real deal; if you want to build a good front-end for your Python data science project as quickly as possible, Streamlit is the clear choice. If you want complete control of layout, aesthetics, user interactions, and compute architecture, Streamlit can feel frustratingly confined.
|Surprise and delight||Friction and frustration|
|Easy to learn and fast development speed. The API is straightforward and the documentation is fantastic.||Can't build complex interactive patterns. No way to define custom callback functions.|
|It just works, right out-of-the-box. Nice defaults for functionality and aesthetics.||Limited control over layout.|
|A recent round of funding and growing user base suggests a stable, popular tool worth the time to learn.||Still working out some of the small bugs. Some key features still in beta.|
Table of contents
- What is a data app framework?
- Streamlit is hot
- Streamlit is impressively easy to learn and use
- Streamlit's functionality is good enough
- Streamlit hosting is just getting started
- Bells, whistles, and gotchas
- Building the demo
- Wrapping up
Streamlit is a data app framework, sometimes called a data dashboarding tool. Data apps are a fantastic way for data scientists to present their results. They give the audience interactive control of visualizations, engaging the user more intuitively with the narrative. Data app frameworks are code-based, which allows for more complexity than BI dashboarding tools. In my demo, for example, I simulate data and use a Bayesian model to analyze an experiment. This kind of model-based visualization is much easier to do with code than with the SQL-plus-GUI combination used by most BI dashboarding tools.
Streamlit the company was in the news recently, announcing a series B funding round of $35 million, bringing their total to $62 million since 2019. The framework seems to be growing quickly in popularity, accruing more GitHub stars (14,500) than any other data app framework except Plotly Dash, in less than two years.
As of this writing, there are over 300 Streamlit-tagged questions on StackOverflow and about 75 posts per week in Streamlit's forum. Updates are released about twice a month, which creates a reassuring sense that any bugs will be hammered out quickly. Lastly, Streamlit's app creation package is free and open-source on Github under a permissive license, so there's little fear the core tool will vanish in the event the company is acquired.
All in all, it seems well worth the investment of time and effort to learn Streamlit, from either the business or professional data science perspective.
The first thing I noticed when starting out with Streamlit is how crisp and clean the documentation is. Just enough detail to get a nice-looking app running, but no more. Even the config file is well-documented.
Streamlit’s API design is equally elegant. Define a simple hierarchy of layout containers (the reactive sidebar is included automatically), then add plots and control widgets with imperative-style commands. Elements appear in their layout container in code order unless otherwise specified.
Streamlit re-runs the whole Python script whenever any app state changes. This enables an impressive level of interactivity without the need for custom callback functions. Widget objects in the code just work; they take whatever value the user chooses in the live app.
As a regular Python user but Streamlit novice, it took me just a few hours to build my first finished prototype. Because app development was so fast, I was able to spend more time thinking about the data science methods and narrative.
There are a couple of small rough edges. Debugging is clunky; I found myself running the app script in an IPython terminal to debug, side-by-side with the rendered version in a browser. Another peccadillo: the displayed value of slider widgets seems to have a minimum step size of 0.01, even when the slider allows for smaller increments. These kinds of things are annoyances, not deal-breakers.
Streamlit’s strong opinions about layout and script execution maximize development speed and get you to “good-enough” functionality very quickly but can leave power users frustrated.
Unlike Plotly Dash, Streamlit does not allow the developer to define custom reactive behavior. In my experience, this is not a super common requirement—it's not part of the demo for this article—but it does come up. One specific use case I've seen is to use brushing, panning, zooming, or point selection on one plot to control the display of other plots in the app. This does not seem possible in Streamlit.
Streamlit's decision to re-run the whole app script when any state changes means slow things like data loading and preprocessing are repeated many times, unnecessarily. The framework mitigates this problem in two ways. First, function outputs can be cached in a lookup table with a simple decorator. When this article was first published, we noted the details about caching were a bit murky, but the company has done a good job filling out the documentation.
The second way to reduce compute time is to use a
container, released just last month. Widgets inside a
form container don't trigger script execution until the user
form_submit_button, so the user can update
several control knobs at once with only a single re-run of the code.
Layout options are limited with Streamlit. The only obvious way to organize content is in columns and on the built-in sidebar. The sidebar is very handy—I have spent way too much time in other frameworks tweaking the layout of control widgets.
I used the Altair plot library for my demo and I'm happy with how the plots turned out. Plotly plots did not work as smoothly; the figures would not resize automatically to the width of their container, despite my best efforts.
For open-source projects, Streamlit (the company) will host the app for free...with limits. This feature, called Streamlit Sharing, is still invite-only, but I received access quickly when I requested it. Like the rest of Streamlit's documentation, the instructions for deploying and app are clear and straightforward; the crux of it is granting Streamlit access to your GitHub account and indicating the correct repo.
Streamlit Sharing is rather limited. Developers are limited to 3 apps, even for open source projects. Apps run on a single CPU with less than 1GB of RAM and storage, so many modern machine learning use cases are not feasible. And of course, most industry data science projects are not open source, so Streamlit Sharing is a non-starter.
Streamlit recently announced a hosting capability for private apps as well, called Streamlit for Teams. It is currently in beta and also invite-only; I have not yet tried it.
- The built-in screencast tool works seamlessly.
- App scripts can be automatically synced to an S3 bucket.
- You can run an app script from a URL (e.g. a Github gist), which is a decent fall-back option for sharing if you can’t deploy from a server.
- Streamlit installs a lot of dependencies.
- By default, Streamlit sends usage statistics back to the mothership. This can be turned off in the config.
- By default, Streamlit watches the entire file system for changes in case a running app needs to be refreshed. The documentation suggests this can be changed, although I didn’t confirm it.
This demo app shows a Bayesian analysis of a simulated staged rollout experiment. Here, I describe the nuts and bolts of the app, but there is also a detailed walk-through of the methodology in a separate article.1
Streamlit apps are Python scripts, run with the Streamlit server. As of this writing, I'm using Python 3.8 and Streamlit 0.81.1. The other requirements and versions are listed in the repo's requirements file.
Streamlit has strong opinions, presumably intended to maximize development speed. One is
that layout is controlled imperatively, with a hierarchy of spatial containers. My app,
for example, starts with the title and a brief description at the top level of the
hierarchy, which is the
streamlit module itself:
1 2 3 4 5 6 7
The sidebar exists by default and is the perfect place for control widgets. Adding these widgets—an integer input and floating point sliders, in my case—follows the same imperative pattern. The variable assigned to the widget takes that widget's value whenever the user changes it, and can then be used later in the script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Creating columns in the main body for plots is a functionality still (explicitly) in beta, but it seems to work nicely. In my case, I want three columns of equal width.
Streamlit's second strong opinion is that the whole Python script is re-run whenever any
app state changes. This means we don't have to write our own callback functions, but it
also means the slow steps of data loading and preprocessing (or simulation, in this
demo) are repeated each time. To avoid this, Streamlit can
cache function outputs in a fast-lookup hash table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
I use the Altair package for the individual plots. They are a bit complex, with multiple layers and tooltips, so I've simplified the code here for brevity. Here is the code for the first plot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Unless otherwise specified, items appear in their layout container in the same order they're written in the code. Now that I have the first figure created, I place it on the canvas as the first element of the left column:
Streamlit can detect if the script is being run with the Streamlit server, or from a REPL. This is very handy for saving static versions of the app plots without duplicating code, although it doesn't seem to be advertised much.
The rest of the code concerns the statistical model and the Altair plots, but—amazingly—that's pretty much all there is to it for the app machinery. To launch it, we run the server from a bash prompt:
$ streamlit run app.py You can now view your Streamlit app in your browser. Local URL: http://localhost:8501
The Crosstab Kite does not accept affiliate or referral fees, so I can say without ulterior motives that Streamlit is a delight to use. Because it's so straightforward to learn and use, it's certainly worth the time to at least try it out. Streamlit's hosting capability is limited; it's reasonable for open source projects, but not really an option for business use cases at this point. We look forward to trying out the commercial product when it's generally available.
In the meantime, don't forget to check out the article about the content of the demo app. Feedback about this review, the app, or the methdology article is welcome, please send comments via our contact page, Twitter, or LinkedIn.