(1) Getting to know Streamlit for the first time (with installation)

This getting started guide explains how Streamlit works, how to install Streamlit on your preferred operating system, and how to create your first Streamlit application!
insert image description here

1 installation

1.1 Prerequisites

Python 3.7 – Python 3.11
**Note: I am using the virtual environment of anaconda here, and write code with pycharm~

1.2 Virtual Environment

step1: Open the anaconda prompt and add a virtual environment

conda create -n streamlit  python=3.7

step2: Check whether the virtual environment has been added

conda env list

step3: Activate the virtual environment

conda activate streamlit #虚拟环境名

step4: install streamlit

pip install streamlit

2 code run

Using Streamlit is simple. First, add some Streamlit commands to a normal Python script, then run it with:

streamlit run your_script.py [-- script args]

Once you run the script as shown above, the local Streamlit server will start and your application will open in a new tab in your default web browser. The app is your canvas where you can draw diagrams, text, widgets, tables and more.
Another way to run Streamlit is to run it as a Python module. This is useful when configuring an IDE like PyCharm to use Streamlit:

# Running
$ python -m streamlit run your_script.py

# is equivalent to:
$ streamlit run your_script.py

3 development process

Save the source file every time you want to update the application. When doing so, Streamlit will detect if there have been changes and ask you if you want to re-run the application. Select "Always Rerun" at the top right of the screen to automatically update the application every time the application's source code is changed.
This allows you to work in a quick interactive loop: you type some code, save it, try it out in real time, type some more code, save it, try it out, and so on until you're happy with the result. The tight loop between coding and seeing the results in real time is one of the ways Streamlit makes your life easier.

When developing a Streamlit application, it is recommended to place the editor and browser windows side by side so that you can see both the code and the application at the same time. try it!

Guess you like

Origin blog.csdn.net/weixin_46043195/article/details/129012108