pythonic生物人

交互式界面工具:shiny、dash、streamlit等怎么选?

仪表盘 (Dashboard),可简单的理解为一个交互式网页,在其中,用户可以不懂代码,拖拖拽拽即可与数据交互、做数据探索建模分析、展示自己关注的结果。

本文

汇总了Python/R/Julia中5款仪表盘 (Dashboard)工具,简单比较其使用场景、学习难度、成熟度、支持语言等。

Image
The GitHub star history of Viola, Dash, Shiny, Streamlit, and Panel.

Dash

Dash和前面介绍的plotly出自同一家公司,可基于Python, R, Julia和 F#语言高效开发仪表盘,为机器学习和数据科学结果提供良好展示;
Dash专注于企业级仪表板的创建,部分功能开源(人名币玩家可尝试全功能企业版本),高级API plotly-express的发布使Dash更容易上手;
一个简单的Python Dash例子,使用熟悉的iris数据集,代码存入dash.t.py中,内容如下,

import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import plotly.express as px

df = px.data.iris()
all_dims = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Dropdown(id="dropdown",
                 options=[{
                     "label": x,
                     "value": x
                 } for x in all_dims],
                 value=all_dims[:2],
                 multi=True),
    dcc.Graph(id="splom"),
])

@app.callback(Output("splom", "figure"), [Input("dropdown", "value")])
def update_bar_chart(dims):
    fig = px.scatter_matrix(df, dimensions=dims, color="species")#plotly.express可视化
    return fig

app.run_server(debug=True)

python dash.t.py
Dash is running on http://xxx/
浏览器中打开 http://xxx/
Image进一步学习:https://github.com/plotly/dash


Streamlit

相较于Dash,Streamlit只能基于Python开发仪表盘,但是完全开源;
比Dash更容易上手,几分钟即可创建一个仪表盘,可节省更多时间做数据分析。
一个简单Python Streamlit例子,求任意数平方,代码存入stre.t.py中,内容如下,

import streamlit as st

x = st.slider('Select a value')
st.write(x, 'squared is', x * x)

streamlit run stre.t.py
You can now view your Streamlit app in your browser.Local URL: http://xx
打开http://xx
Image更复杂的例子,利用自动驾驶数据集,使用YOLO做对象检测,

Image

进一步学习:https://github.com/streamlit/streamlit


Shiny

Shiny是R中的工具,能非常友好的融合R中的其它工具,譬如ggplot2等,推荐R用户使用;
Shiny功能不及Dash强大,特别是Dash的企业收费版本。
一个例子,和ggplot2一样,创建的页面非常优雅,

Image

进一步学习:https://github.com/rstudio/shiny

https://shiny.rstudio.com/tutorial/


Voila

Jupyter Notebook重度玩家首选,Voila快速将Jupyter Notebook变成仪表盘;
Voila非常
轻量级,当需要将Jupyter Notebook结果展示给非技术团队时推荐。

Python Voila一个简单例子,

Image

进一步学习:https://github.com/voila-dashboards/voila


Panel

需要快速将Jupyter Notebook变成仪表盘,但是Voila又不能充分满足这个需求时,推荐Panel。
进一步学习:https://github.com/holoviz/panel
Image


比较结果

比较结果汇总,参考6个指标 :

  • 成熟度 (Maturity)
  • 知名度 (Popularity)
  • 上手难度 (Simplicity)
  • 应用灵活度 (Adaptability)
  • 聚焦场景 (Focus)
  • 支持语言 (Language support)

结果划分分A、B、C三个等级:Image

-END-
推荐阅读:

Image

我的学习小圈子👉
加入

Image

赞、在看就是最大的支持Image