Hi, Community!
In this article, I will introduce Python Streamlit Web Framework.
Below, you can find the topics we will cover:
- 1-Introduction to Streamlit Web Framework
- 2-Installation of?Streamlit module
- 3-Running Streamlit Application
- 4-Streamlit Basic commands
- 5-Display multimedia?
- 6-Input widgets
- 7-Display progress and status
- 8-Sidebar and container
- 9-Data Visualization
- 10-Display a DataFrame
?
So, let's start with the first topic.
1-Introduction to Python Streamlit?Web Framework?
Streamlit?is an open-source Python framework that allows data scientists and machine learning engineers to create interactive web applications quickly and easily.
With its simple syntax and effortless integration with popular data science libraries, Streamlit has become the front-runner for prototyping and sharing projects.
For more details please view Streamit Documentations
2-Installation of?Streamlit module
Before we start building our Streamlit Web Application, we need to install the module using the pip package installer.
To install Streamlit, run the following command:
pip install streamlit
Below there is the command to test the installation:?
streamlit hello
When you type the command mentioned above in the terminal, the following page should open automatically:
?
3-Running Streamlit Application
Working with Streamlit is straightforward. First, you sprinkle a few Streamlit commands into a normal Python script, then you run it with?streamlit run:
pip install streamlit
As soon as you run the script, a local Streamlit server will spin up and your app will open in a new tab in your default web browser. ?Please note that the app is your canvas, where you will draw charts, texts, widgets, tables, and more.
Another way of running Streamlit is doing so as a Python module. This can come in handy when configuring an IDE, e.g., PyCharm to work with Streamlit:
streamlit hello
Remember to save the source file whenever you wish to update your app. When you do so, Streamlit detects a change if any, and asks you whether you want to rerun your app. Select "Always rerun" at the top-right of your screen to automatically update your app each time you modify its source code. It will allow you to work in a fast interactive loop: you type some code, save it, try it out live, then type some more code, save it, try it out, and so on until you are happy with the results. This tight loop between coding and viewing results live is one of the ways Streamlit makes your life easier.
4-Streamlit Basic commands
Display texts with Streamlit
st.write(): This function adds anything from formatted strings to charts in Matplotlib figures, Altair charts, Plotly figures, data frames, Keras models, and others to a web app.
Let's create main.py file below:
streamlit run your_python_file.py
Run the main.py file by operating the following command:
python -m streamlit run your_python_file.py
st.title(): This function allows you to add the title to the app.?
st.header(): This function is used to assign the header of a section.
st.markdown(): This function is utilized to set a markdown of a section.?
st.subheader(): This function is employed to set the sub-header of a section.
st.caption(): This function is used to write captions.
st.code():?This function is utilized to set a code.??
st.latex(): This function displays mathematical expressions formatted as LaTeX.?
import streamlit as st st.write("Hello ,let's learn how to build a streamlit app together")
5-Display multimedia?
Below we listed some functions to display images, videos, and audio files.
st.image(): This function is employed to depict an image.
st.audio(): This function is utilized?to display an audio.?
st.video(): This function is used to show a video.
streamlit run main.py
6-Input widgets
Widgets are the most significant user interface components. Streamlit has various widgets that allow you to build interactivity directly into your apps with buttons, sliders, text inputs, and more.
st.checkbox(): This function returns a Boolean value. When the box is checked, it returns a True value. Otherwise, it sends back a False value.
st.button(): This function is used to display a button widget.?
st.radio(): This function exhibits a radio button widget.?
st.selectbox(): This function is utilized to demonstrate a select widget.?
st.multiselect(): This function is used to display a multi select widget.?
st.select_slider(): This function is used to display a select slider widget.?
st.slider(): This function is used to display a slider widget.
pip install streamlit
st.number_input(): This function displays a numeric input widget.
st.text_input(): This function exhibits a text input widget.
st.date_input(): This function reveals a date input widget to choose a date.
st.time_input(): This function exposes a time input widget to select a time.
st.text_area(): This function shows a text input widget with more than a line of text.
st.file_uploader(): This function is operated to demonstrate a file uploader widget.
st.color_picker(): This function is operated to demonstrate a file uploader widget.
streamlit hello
7-Display progress and status
At this point, we will explain how to add a progress bar and such status messages as error and success to our app.
st.balloons(): This function is used to display balloons for celebration.?
st.progress(): This function is utilized to show a progress bar.?
st.spinner(): This function demonstrates a temporary waiting message during execution.
streamlit run your_python_file.py
st.success(): This function exhibits a success message.
st.error(): This function is used to demonstrate an error message.?
st.warning(): This function is utilized to display a warning message.
st.info(): This function reveals an informational message.
st.exception(): This function is operated to show an exception message.
pip install streamlit
8-Sidebar and container
We can additionally create a sidebar or a container on your page to organize your app. The hierarchy and arrangement of pages on your app can have a huge impact on your user experience. Organizing your content allows visitors to understand your site better and navigate it easier. It also helps them find what they are looking for faster and increases the likelihood that they will return.?
Sidebar
Passing an element to?st.sidebar()?will pin this element to the left, allowing users to focus on the content making your app more organized and easier to deal with.
streamlit hello
Container
st.container()?is employed to construct an invisible container where you can put elements creating a useful arrangement and hierarchy.
streamlit run your_python_file.py
python -m streamlit run your_python_file.py
9-Data Visualization
Data visualization simplifies telling stories by curating data into a more straightforward format, highlighting the trends and outliers. A good visualization conveys a narrative, removing the noise from data and emphasizing the valuable information. However, it is way more complicated than just dressing up a graph to make it look better or slapping on an infographic's "info" part.
Effective data visualization is a delicate balancing act between form and function. A plain graph could be too boring to draw attention or communicate a powerful message, whereas the most stunning visualization could fail to deliver the right idea. The data and visuals need to work together. However, combining great analysis with excellent storytelling is an art.?
st.pyplot(): This function is used to display a matplotlib.pyplot figure.
pip install streamlit
st.line_chart(): This function is utilized to show a line chart.
streamlit hello
st.bar_chart(): This function is employed to exhibit a bar chart.
streamlit run your_python_file.py
st.map(): This function displays maps in the app. However, it requires the values of latitude and longitude which cannot be null/NA.
python -m streamlit run your_python_file.py
10-Display a DataFrame
st.dataframe(): This command shows a DataFrame as an interactive table. It works with a variety of collection-like and DataFrame-like object types.
import streamlit as st st.write("Hello ,let's learn how to build a streamlit app together")
You can also pass a Pandas Styler object to change the style of the rendered DataFrame:
streamlit run main.py
Summary
In this article, after introducing the Streamlit web framework, I demonstrated how to install Streamlit and run the application. We also explored some basic commands, widgets, and data visualization functionality.
In my next article, we will create a Streamlit web application to connect to the IRIS dataset and explore advanced concepts of Streamlit together.
Thanks
The above is the detailed content of Getting to know Python Streamlit Web Framework. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Dynamic programming (DP) optimizes the solution process by breaking down complex problems into simpler subproblems and storing their results to avoid repeated calculations. There are two main methods: 1. Top-down (memorization): recursively decompose the problem and use cache to store intermediate results; 2. Bottom-up (table): Iteratively build solutions from the basic situation. Suitable for scenarios where maximum/minimum values, optimal solutions or overlapping subproblems are required, such as Fibonacci sequences, backpacking problems, etc. In Python, it can be implemented through decorators or arrays, and attention should be paid to identifying recursive relationships, defining the benchmark situation, and optimizing the complexity of space.

Python's socket module is the basis of network programming, providing low-level network communication functions, suitable for building client and server applications. To set up a basic TCP server, you need to use socket.socket() to create objects, bind addresses and ports, call .listen() to listen for connections, and accept client connections through .accept(). To build a TCP client, you need to create a socket object and call .connect() to connect to the server, then use .sendall() to send data and .recv() to receive responses. To handle multiple clients, you can use 1. Threads: start a new thread every time you connect; 2. Asynchronous I/O: For example, the asyncio library can achieve non-blocking communication. Things to note

The core answer to Python list slicing is to master the [start:end:step] syntax and understand its behavior. 1. The basic format of list slicing is list[start:end:step], where start is the starting index (included), end is the end index (not included), and step is the step size; 2. Omit start by default start from 0, omit end by default to the end, omit step by default to 1; 3. Use my_list[:n] to get the first n items, and use my_list[-n:] to get the last n items; 4. Use step to skip elements, such as my_list[::2] to get even digits, and negative step values ??can invert the list; 5. Common misunderstandings include the end index not

Python's datetime module can meet basic date and time processing requirements. 1. You can get the current date and time through datetime.now(), or you can extract .date() and .time() respectively. 2. Can manually create specific date and time objects, such as datetime(year=2025, month=12, day=25, hour=18, minute=30). 3. Use .strftime() to output strings in format. Common codes include %Y, %m, %d, %H, %M, and %S; use strptime() to parse the string into a datetime object. 4. Use timedelta for date shipping

Polymorphism is a core concept in Python object-oriented programming, referring to "one interface, multiple implementations", allowing for unified processing of different types of objects. 1. Polymorphism is implemented through method rewriting. Subclasses can redefine parent class methods. For example, the spoke() method of Animal class has different implementations in Dog and Cat subclasses. 2. The practical uses of polymorphism include simplifying the code structure and enhancing scalability, such as calling the draw() method uniformly in the graphical drawing program, or handling the common behavior of different characters in game development. 3. Python implementation polymorphism needs to satisfy: the parent class defines a method, and the child class overrides the method, but does not require inheritance of the same parent class. As long as the object implements the same method, this is called the "duck type". 4. Things to note include the maintenance

The "Hello,World!" program is the most basic example written in Python, which is used to demonstrate the basic syntax and verify that the development environment is configured correctly. 1. It is implemented through a line of code print("Hello,World!"), and after running, the specified text will be output on the console; 2. The running steps include installing Python, writing code with a text editor, saving as a .py file, and executing the file in the terminal; 3. Common errors include missing brackets or quotes, misuse of capital Print, not saving as .py format, and running environment errors; 4. Optional tools include local text editor terminal, online editor (such as replit.com)

TuplesinPythonareimmutabledatastructuresusedtostorecollectionsofitems,whereaslistsaremutable.Tuplesaredefinedwithparenthesesandcommas,supportindexing,andcannotbemodifiedaftercreation,makingthemfasterandmorememory-efficientthanlists.Usetuplesfordatain

To generate a random string, you can use Python's random and string module combination. The specific steps are: 1. Import random and string modules; 2. Define character pools such as string.ascii_letters and string.digits; 3. Set the required length; 4. Call random.choices() to generate strings. For example, the code includes importrandom and importstring, set length=10, characters=string.ascii_letters string.digits and execute ''.join(random.c
