Streamlit介绍
Streamlit 是一个用于创建数据科学和机器学习应用程序的 Python 库。它提供了一个简单易用的界面,让用户能够快速创建交互式数据可视化和 Web 应用程序,而无需编写复杂的前端代码。Streamlit 支持一系列常用的数据科学和机器学习库,如 Pandas、NumPy、Matplotlib、Seaborn、Scikit-learn 等,并且能够与 Jupyter Notebooks 和 Python 脚本相集成,方便用户快速将其现有的代码集成到 Streamlit 应用程序中。
通俗讲就是可以不会前端技术(HTML,CSS,JS),0基础写Web网页。
安装前准备
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) yum install wget -y yum install gcc openssl-devel bzip2-devel libffi-devel xz-devel -y
由于7系统自带的是Python2.7.5,所以需要安装python3.8
wget https://www.python.org/ftp/python/3.8.14/Python-3.8.14.tgz tar -xzvf Python-3.8.14.tgz cd Python-3.8.14 ./configure --enable-optimizations make altinstall
安装完成运行python3.8命令以及升级安装pip
python3.8 -V pip3.8 install --upgrade pip pip3 -V
正式安装Streamlit
pip3 install numpy pip3 install pandas pip3 install streamlit streamlit --version
报错解决,降低urllib3版本
streamlit hello python -c "import ssl; print(ssl.OPENSSL_VERSION)" pip uninstall urllib3 pip install urllib3==1.26.6
防火墙开放80端口
firewall-cmd --permanent --add-service=http firewall-cmd --reload
运行hello测试
streamlit hello
Ctrl+C终止,指定端口80运行
streamlit hello --server-port=80 vi first_app.py
import streamlit as st # To make things easier later, we're also importing numpy and pandas for # working with sample data. import numpy as np import pandas as pd """ # My first app Here's our first attempt at using data to create a table: """ df = pd.DataFrame({ 'first column': [1, 2, 3, 4], 'second column': [10, 20, 30, 40] }) df chart_data = pd.DataFrame( np.random.randn(20, 3), columns=['a', 'b', 'c']) st.line_chart(chart_data) option = st.selectbox( '您最喜欢哪个数字?', df['first column']) 'You selected: ', option
运行first_app.py代码
streamlit run first_app.py --server.port 80
打开谷歌浏览器,输入centos的IP地址就可以访问你写的first_app.py,应当如下
发表评论