Dash类似R语言中的Shiny包,可以使用纯Python代码而不需要学习HTML、CSS、JavaScript语言就可以快速搭建一个网站,dash-bootstrap-components是Dash的拓展,提供了很多特性。
official site
Dash
https://dash.plotly.com/
dash-bootstrap-components(dbc)
https://dash-bootstrap-components.opensource.faculty.ai/
conda环境配置
我一直使用的是micromamba,因为比conda速度快,语法和conda一样,其中Dash网站所需要的4个包名字是dash开头,其他包是平时数据分析所需要用的;这里并未指定Python版本,自动安装的python是最新版3.10。
micromamba create -n dash;micromamba activate dash
micromamba -y install -c anaconda ipywidgets pandas numpy seaborn scikit-learn
micromamba -y install -c conda-forge matplotlib ipykernel dash dash-core-components dash-html-components dash-bootstrap-components
Dash网页APP初试
这里使用的是dbc官网的案例,模仿Shiny包使用KMeans给iris数据集聚类。
先不用管代码怎么写的,先跑起来。
新进一个文件iris_dash.py把下边代码复制进去。
"""
Dash port of Shiny iris k-means example:
https://shiny.rstudio.com/gallery/kmeans-example.html
"""
import dash
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.grap