5 Streamlit Components To Build Better Applications

 Streamlit is an amazing Python library.

I daily use it to build and share interactive web applications that solve various tasks: interacting with user inputs and understanding the predictions of a machine learning model, providing an interface for visualizing and exploring data, sharing automated reports, and much more.

What makes Streamlit even more powerful is the large set of plugins (also called Streamlit components) that the open-source community develops and maintains.

In this post, I’ll be reviewing 5 Streamlit components that I often use to extend Streamlit native functionalities. We’ll understand what these libraries exactly accomplish and when you should use them.

If you’re a Streamlit user, you should definitely check this post.

Without much further ado, let’s have a look 👀

Streamlit components — what are they?

You can go to this link and check the most popular components that the community open-sourced.

Screenshot by the author

➡️ This is beyond the scope of this post, but if you’re interested in building your own custom Streamlit component, you can watch these two video tutorials that explain the process pretty well.

Part 1
Part 2

Let’s now go through the list. Some of these components are not featured on the official documentation but you can still give them a try 😉.

👉 1 — streamlit_tags

Custom tag/keywords component for Streamlit

pip install streamlit-tags

Streamlit doesn’t natively allow you to input a list of words and retrieve this data as a python list in the backend. However, a common workaround exists: you get the user input through a st.text_input or st.text_area then you parse it with respect to a given separator and get a list.

But this seems like unnecessary work.

streamit_tags allows you to directly get the keywords from the interface as shown in the following example.

Image by the author

When would you need to use streamlit-tags?

👉 2 — streamlit_aggrid

A Streamlit wrapper around the Ag-Grid JS library

Github: https://github.com/PablocFonseca/streamlit-aggrid

pip install streamlit-aggrid

streamlit_aggrid is a component that is built on top of AG Grid (a highly customizable JavaScript data grid) and it’s meant to improve Streamlit capabilities in terms of displaying dataframes and interacting with them.

Using streamlit_aggrid is as simple as importing the AgGrid function and passing a dataframe to it:

from st_aggrid import AgGridAgGrid(df)

Here are some of AgGrid features:

  • Columns can be sorted, filtered and searchable:
GIF by the author
  • You can drag columns and change their order: this can be useful when analyzing data
GIF by the author
  • Large dataframes can be paginated
GIF by the author
  • You can pin columns, group them and compute aggregations — directly from the browser
GIF by the author
  • You can make your dataframes interact with the rest of the Streamlit widgets (by selecting a row for example)
GIF by the author

These GIFs have been taken from one of my previous posts. If you’re interested in learning more about streamit_aggrid, you can check it out.

When would you need to use streamlit-aggrid?

👉 3 — streamlit-echarts

A Streamlit component to render ECharts plots.

Github: https://github.com/andfanilo/streamlit-echarts

pip install streamlit-echarts

You’ve probably used Matplotlib, Bokeh, or Plotly when you had to make data visualizations in Streamlit: these are the most popular choices.

Another option I recently came across is Echarts: an amazing interactive charting and data visualization library. It’s written in JavaScript and is maintained by the Apache foundation.

Echarts provides powerful visualization capabilities with endless customization. You can use it to draw lines, bar charts, pie charts, scatter plots, geographical heatmaps, radar plots, directed graphs, treemaps, Sankey graphs, gauges, parallel plots, and many other crazy things.

The syntax is also quite simple to understand and adapt.

If you’re curious, you can check what you can do with echarts here.

Screenshot by the author

streamlit-echarts is the component you’ll need to integrate Echarts plots in your Streamlit apps.

I’ve played a bit with this component and I must say that it’s quite easy to use.
Let me show you an example.

Imagine that you want to embed a gauge, like the following one (code available here from the official examples)

Screenshot by the author

All you have to do is convert the following JSON object (from the left pane):

JS Object

to a Python dictionary:

Python Dict

Then, you’ll have to pass this dictionary to st_echarts

from streamlit_echarts import st_echarts
st_echarts(options=options, width="100%", key=0)

And the result looks quite good on Streamlit.

Screenshot by the author

When would you need to use streamlit-echarts?

  • If you have some JS knowledge, you can build very sophisticated plots and customized layouts

👉 4 — streamlit-pandas-profiling

pandas-profiling into your Streamlit app — with a one line of code

pip install streamlit-pandas-profiling

pandas-profiling has been around for a few years now. It’s a Python library that allows you to build HTML reports from your Pandas Dataframes objects. It’s very useful because it automates a lot of tasks we repeatedly perform to analyze data, compute statistical metrics, create plots, spot correlations, anomalies, or missing data.

Integrating pandas-profiling inside Streamlit is actually not a bad idea at all. I found myself many times creating exploratory data analysis (EDA) dashboards from scratch in Streamlit and this component would have saved a lot of time.

The integration between these two libraries is very smooth as shown in the animated GIF below:

GIF by the author

When would you need to use streamlit-pandas-profiling?

👉 5 — st-annotated-text

A Streamlit component to display annotated text

pip install st-annotated-text

st-annotated-text is an interesting component that allows you to highlight specific portions of a text, and attribute a label and a color to it. If you work on NLP tasks such as Named Entity Recognition (NER) or POS tagging, this package comes in handy.

Screenshot by the author

When would you need to use st-annotated-text?

st-annotated-text provides useful visual information in this context by annotating each entity.

Screenshot by the author

If you’re interested in learning more about this app, you can check my post:

Resources

Thanks for reading 🙏

That’s all for me today. Until next time! 👋

Comments

Popular posts from this blog

Flutter for Single-Page Scrollable Websites with Navigator 2.0

A Data Science Portfolio is More Valuable than a Resume

Better File Storage in Oracle Cloud