plotly-dash 简单使用(一)
plotly-dash 是一个很不错的dashboard 开发平台,基于python 编写,提供了很便捷的dashboard 开发模型
同时扩展上也比较灵活我们可以编写自己的组件。
以下是一个简单的项目以及集成docker 运行(实际通过gunicorn,uwsgi运行应用)
本地方式运行
使用venv 进行python 环境管理
- 初始化venv 项目
- python3 -m venv venv
- 激活环境
- source venv/bin/activate
- 添加依赖
- pip install dash==1.1.1
- pip install dash-daq==0.1.0
- 简单代码
- # -*- coding: utf-8 -*-
- import dash
- import flask
- import dash_core_components as dcc
- import dash_html_components as html
- server = flask.Flask(__name__)
-
- external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
- app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
- server = app.server
- app.layout = html.Div(children=[
- html.H1(children='Hello Dash'),
-
- html.Div(children='''
- Dash: A web application framework for Python.
- '''),
-
- dcc.Graph(
- id='example-graph',
- figure={
- 'data': [
- {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
- {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
- ],
- 'layout': {
- 'title': 'Dash Data Visualization'
- }
- }
- )
- ])
-
- if __name__ == '__main__':
- app.run_server(debug=False)
- 启动
- python app.py
- 效果
- * Serving Flask app "app" (lazy loading)
- * Environment: production
- WARNING: This is a development server. Do not use it in a production deployment.
- Use a production WSGI server instead.
- * Debug mode: off
- * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
docker 运行
docker 提供了两种方式的运行,gunicorn以及uwsgi
- docker-compose 文件
- version: "3"
- services:
- dash-gunicorn:
- build: ./
- image: dalongrong/dash-demo:gunicorn
- ports:
- - "5000:5000"
- dash-uwsgi:
- build:
- context: ./
- dockerfile: Dockerfile-uwsgi
- image: dalongrong/dash-demo:uwsgi
- ports:
- - "5001:5001"
- gunicorn 方式dockerfile
- FROM python:3.5.7-alpine
- RUN pip install dash==1.1.1 \
- && pip install dash-daq==0.1.0 \
- && pip install gunicorn
- WORKDIR /app
- COPY . /app
- EXPOSE 5000
- ENTRYPOINT [ "gunicorn","-b",":5000","app:server"]
- uwsgi 方式dockerfile
- FROM python:3.5.7-alpine
- RUN apk add --no-cache uwsgi uwsgi-python3 uwsgi-http
- RUN pip install dash==1.1.1 \
- && pip install dash-daq==0.1.0
- WORKDIR /app
- COPY . /app
- EXPOSE 5001
- ENTRYPOINT [ "uwsgi","--plugins","http,python3","--http","0.0.0.0:5001","--module","app:server","--pythonpath","/usr/local/lib/python3.5/site-packages"]
- 运行
- docker-compose build
- docker-compose up -d
- 效果
- 几点说明
使用uwsgi的时候碰到了pip 包查找的问题,问题如下:
- Traceback (most recent call last):
- dash-uwsgi_1 | File "./app.py", line 2, in <module>
- dash-uwsgi_1 | import dash
- dash-uwsgi_1 | ModuleNotFoundError: No module named 'dash'
- dash-uwsgi_1 | unable to load app 0 (mountpoint='') (callable not found or import error)
- dash-uwsgi_1 | *** no app loaded. going in full dynamic mode ***
解决方法,添加pythonpath 如下:
- ENTRYPOINT [ "uwsgi","--plugins","http,python3","--http","0.0.0.0:5001","--module","app:server","--pythonpath","/usr/local/lib/python3.5/site-packages"]
uwsgi 只安装了uwsgi python 无法运行,问题
- uwsgi http is ambiguous
问题原因,因为我是通过alpine 的apk 安装的,需要添加http 以及python 的支持,解决方法
- RUN apk add --no-cache uwsgi uwsgi-python3 uwsgi-http
注意对于python模块的支持需要uwsgi-python3 因为我们使用的是python3 的基础镜像
说明
plotly-dash 功能很强大,开发模型也比较简单,后边会写一些相关的学习
参考资料
https://stackoverflow.com/questions/35460816/uwsgi-http-is-ambiguous
https://uwsgi-docs.readthedocs.io/en/latest/Python.html
https://dash.plot.ly/installation
https://github.com/rongfengliang/plot_dash_docker_running
plotly-dash 简单使用(一)的更多相关文章
- Python绘图工具Plotly的简单使用
1.Plotly被称为史上最好的绘图工具之一,为了更好的展示金融数据的复杂性. Plotly的官方网站为:https://plot.ly/ python量化的关键是金融数据可视化,无论是传统的K线图, ...
- Dash by Plotly 学习笔记
一.介绍 1.dash 是什么 dash 是一个基于 Flask (Python) + React 的 web 框架. 入门指南:https://dash.plot.ly/getting-starte ...
- 【python】使用plotly生成图表数据
安装 在 ubuntu 环境下,安装 plotly 很简单 python 版本2.7+ pip install plotly 绘图 在 plotly 网站注册后,可以直接将生成的图片保存到网站上,便于 ...
- 一些开源的dashboard 解决方案
简单收集了以下开源dashboard 的项目,记录下 plotly-dash 基于python 的dash 开发工具,很不错 项目地址 https://github.com/plotly/dash k ...
- Python开源项目Top30
原文地址:https://www.cnblogs.com/stoker/p/9101825.html No 1:Home-assistant (v0.6+) 基于Python 3的开源家庭自动化平台[ ...
- 10个顶级Python实用库,推荐你试试!
为什么我喜欢Python?对于初学者来说,这是一种简单易学的编程语言,另一个原因:大量开箱即用的第三方库,正是23万个由用户提供的软件包使得Python真正强大和流行. 在本文中,我挑选了15个最有用 ...
- Streamlit:快速数据可视化界面工具
目录 Streamlit简介 Streamlit使用指南 常用命令 显示文本 显示数据 显示图表 显示媒体 交互组件 侧边栏 缓存机制 Streamlit使用Hack Streamlit的替代品 相关 ...
- 数据处理一条龙!这15个Python库不可不知
如果你是一名数据科学家或数据分析师,或者只是对这一行业感兴趣,那下文中这些广受欢迎且非常实用的Python库你一定得知道. 从数据收集.清理转化,到数据可视化.图像识别和网页相关,这15个Python ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- 野路子码农系列(3)plotly可视化的简单套路
又双叒叕要跟客户汇报了,图都准备好了吗?matplotlib出图嫌丑?那用用plotly吧,让你的图看上去经费爆炸~ P1 起因 第一次接触plotly这个库是在我们做的一个列车信号数据挖掘的项目里, ...
随机推荐
- MQTT和Coap
什么是MQTT? MQTT是一个“发布和订阅”协议.用户可以订阅某些主题,或发布某些主题的消息.订阅者将收到订阅的主题消息.用户可以通过保证交付来配置协议更可靠. 什么是CoAP? CoAP看起来像是 ...
- mysql 中的 not like 另一种简化方法。
第一种 not like 方法 select * from table where `zongbu` not like '%北京%' and `zongbu` not like '%上海%' and ...
- SQL Server 新增自动执行任务
第一步右击SQL Server代理,新建作业 第二步选择常规,给你要执行的计划命名 第三步选择步骤,然后给步骤命名,选择类型,数据库,输入你要执行的语句. 第四步设置要执行的频率,根据业务需要,一般建 ...
- Javascript文件上传插件
jQuery File Uploader 这是最受欢迎的 jQuery 文件上传组件,支持批量上传,拖放上传,显示上传进度条以及校验功能. 支持预览图片.音频和视频,支持跨域上传和客户端图片缩放,支持 ...
- dubbo循序渐进 - yml配置
Dubbo首先使用com.alibaba.dubbo.config.spring.schema.NamespaceHandler注册解析器,当spring解析xml配置文件时就会调用这些解析器生成对应 ...
- a属性+DOM创建回流+动画运动+
超链接a的属性 href分析: < a href = " " > 点击刷新页面,相当于向后台发送了一次请求 < a href = " # &quo ...
- 【开发笔记】- 在Grails下查看打印真实的SQL
以往我们都是在hibernate里面开启sql,在grails里面只需要在 DataSource.groovy 里面的一个dataSource加入一个 logSql = true即可,但是这样加后发出 ...
- 【转载】C#通过InsertAt方法在DataTable特定位置插入一条数据
在C#中的Datatable数据变量的操作过程中,可以通过DataTable变量的Rows属性的InsertAt方法往DataTable的指定位置行数位置插入一个新行数据,即往DataTable表格指 ...
- Shell 编程 基础
本篇主要写一些shell脚本的基础知识,编程规范. 第一个shell脚本 [root@localhost ~]# vim first.sh #!/bin/bash # This is first Sh ...
- Django 之restfromwork 源码---APIView 分析
Django 之 djangorestframework的APIView分析 APIView 类中的as_view() 方法 首先 我们从视图函数入手,在urls.py 中的 URLconfig中添加 ...