Recently, I've been experimenting with some of my data analysis tasks with the long-knownStreamlit
And once again, I feelPython
The powerful thing about it.
So, get ready to write an introduction based on your mastery ofStreamlit
The Series.
This article is the first to introduce theStreamlit
What it is, and what it has to do withJupyter
cap (a poem)Traditional Web ApplicationsThe difference.
1. What it is
Streamlit
is a Python library for rapidly building data science and machine learning applications.
utilizationStreamlit
We can use a simplePython
Code to create interactive and visual applications without having to have an in-depth knowledge of front-end technologies or writing large amounts of underlying code.
Streamlit
The history of the development of theOctober 2019at that timeStreamlit
is released as an application development framework specifically for machine learning and data science.
The initial design goal was to replaceFlask
place in machine learning projects and help machine learning engineers rapidly develop user interaction tools.
Streamlit
The core idea is "Scriptability
", i.e., users can build a complete application by writing simple Python scripts.
So.Streamlit
It encapsulates a large number of interactive components and supports rendering of objects such as tables, charts, datasheets, etc., and has rasterized responsive layout capabilities.
Subsequently.Streamlit
evolved and received a lot of attention from the data science community.
Its open-source nature and clean and efficient design philosophy are favored by a growing number of data scientists and developers who use theStreamlit
Create and share a variety of beautiful, interactive web applications.
Streamlit
It is also starting to support a growing number of data visualization libraries such asMatplotlib
、Plotly
cap (a poem)Altair
etc., making it very easy to integrate rich charts and visualization elements in your application.
It is worth noting thatStreamlit
In the course of its development it has also experienced beingSnowflake
important event of the acquisition.
This acquisition further boosts theStreamlit
Applications and developments in data science and machine learning.
For me, usingStreamlit
The great thing is that anyone who knows Python can build a nice interactive application that
No need to get stuck in the pain of writing a front-end and tossing around half a dozen times to adjust a style.
2. Where it is used
In my own experience of usingStreamlit
It is used in two main places.
One is in data analytics and machine learningEarly days of the projectUseStreamlit
Quickly build an app to explore the possibilities in your project.
It can also be used for prototyping projects, which is much better than making static prototypes, on the one hand, you can easily implement a variety of interactions that
On the other hand, one of the charting components can show the results dynamically, better demonstrating to the client the possible effects of the project.
Another place where it can be used isTeaching DemonstrationFor example, when you want to do an online course, it allows the instructor to easily convert complex data into visual charts and images, helping the participants to better understand the data and the knowledge behind it.
Meanwhile.Streamlit
The interactive nature of the interface allows learners to manipulate and explore the interface in real time, which greatly enhances the engagement and interactivity of learning.
In addition.Streamlit
It also supports the integration of multiple data science libraries and tools, enabling instructors to freely select and combine different tools according to their teaching needs, further enriching the content and form of teaching.
For applications with a certain scale of users, such as those requiring authentication, permissions, and other business functions, thenot recommendedutilizationStreamlit
。
After all, the traditional front-end and back-end development methods are still easier to cope with frequent changes in the business, and also conducive to collaborative development.
3. Comparison with Jupyter
utilizationStreamlit
Previously, I used it more early on in the project withJupyter notebook
。
Jupyter
It's also interactive, allowing you to look at the results while coding, and it can be combined with themarkdown
Write some instructional documents.
After using it, I feel that the main differences between the two are:
3.1 Interactivity
Streamlit
Provides a clean user interface in which various controls (e.g. buttons, sliders, etc.) can be easily added.
(indicates contrast)Jupyter
Is organized in notebooks with code, text and visual output. Supports on-the-fly execution of code blocks and presentation of results.
In comparison.Jupyter
is shared as code, which is better suited for trying out various data analysis paths on your own, as well as sharing among developers.
Streamlit
Sharing in the form of an app does not require knowledge of the code and allows you to directly manipulate the interface, making it more suitable for sharing with clients.
3.2 Visualization capabilities
Streamlit
Built-in rich visualization components, support for multiple chart types and interactive data presentation, you can easily present the data analysis results to the user in the form of charts.
Jupyter
Various visualization charts need to be generated through code blocks, usually by importing other third-party libraries (e.g., matplotlib, seaborn, etc.) to help implement them. Its visualization capabilities depend heavily on the libraries used and the developer's programming skills.
In comparison.Streamlit
Requires somewhat less programming skills from the developer, as it is much easier to use built-in packaged components than to use third-party visualization libraries directly.
3.3 Extensibility
Streamlit
In itself, it's purePython
code file, so it's easy to convert an existingPython
Code to integrate intoStreamlit
in the application and enhance the application by adding controls and visualization components.
Jupyter
is a block of code organized in the form of a notebook, and is not pure Python code; code reuse and extension relies more on the combination of the block and the editing of the notebook, which requires more consideration.
In comparison.Streamlit
Expansion is simpler, and after the complexity of the functionality is increased, encapsulating some of the generic functionality and laying out the code structure is more intuitive.
4. Comparison with Web applications
Streamlit
Functions are betweenJupyter
and traditional web applications thanJupyter
Strong but weaker than traditional web applications.
I haven't done much data analytics and machine learning related web apps lately, so I may not have given much thought to comparing the two.
Streamlit
of interactivity has been mentioned in the previous section.Traditional Web ApplicationsIt goes without saying that there is almost no upper limit to the interactivity, just look at the wide variety of Web applications on the Internet nowadays.
However, for developers focusing on the data analytics and machine learning aspects of the
Traditional Web Applicationsdevelopment is overly difficult, requiring not only mastery of multiple technologies and tools, but also the writing of large amounts of front-end and back-end code, as well as complex debugging and testing.
The other two points mentioned in the previous section.visualization capabilitycap (a poem)scalability。
Traditional Web ApplicationsThe ones that can do it are also certainly better thanStreamlit
Strong, web applications have evolved over the years.
Especially with the rapid growth of front-end in recent years, theweb applicationIt can be used for a variety of complex games, as well as e-commerce platforms with complex business, and so on.
The question remains how difficult it is to develop, and the choice has to depend on how complex your application is and whether your team can cover the development of theweb applicationThe types of technology needed.
5. Summary
Overall.Streamlit
,Jupyter
cap (a poem)Traditional Web ApplicationsEach of the three has its own suitable application scenarios, and not one can completely replace the other.
You can refer to the chart below for details on how to choose:
For individuals or students focusing on a data analytics and machine learning orientationStreamlit
Definitely worth a try.