1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

plotly Dashをインストールする

Last updated at Posted at 2019-05-10

はじめに

この記事はMac OSX High Sierraにインストールした Python3.6.8(venv)での内容です。
インストール対象の plotly Dashのバージョンは 0.42.0 です。

plotly Dash の紹介記事をぐぐると古いバージョンの記事がよく出てきますが、現在のバージョン 0.42.0 ではインストール方法が違ってきますので紹介します。

0.37.0 以降のバージョンの Dash では、dash-renderer, dash-core-components, dash-html-components, dash-table は自動的にインストールされるため、それぞれインストールする必要はありません。

インストール手順

pip install dash==0.42.0
pip install dash-daq==0.1.0

ここでインストールしている dash-daq はデータ収集やコントロールを Dash に簡単に統合できるようにするコントロールセットです。
※ plotly がインストールされていなくても、ここで一緒にインストールしてくれます。

サンプルを実行

dash-app.py
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

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=True)

このサンプルを Terminal から実行します。

$ python dash-app.py 
Running on http://127.0.0.1:8050/
Debugger PIN: 612-464-482
 * Serving Flask app "dash-app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
Running on http://127.0.0.1:8050/
Debugger PIN: 500-302-361

WARNING が出ていますが、開発環境を運用環境で使用しないでください。という意味なので気にしないでください。

この状態で http://127.0.0.1:8050 にアクセスします。
スクリーンショット 2019-05-11 07.02.04.png
こういう画面が表示されれば成功です。
実際にグラフも動かしたりできますので色々と試してみてください。

参考サイト

https://dash.plot.ly/installation
https://dash.plot.ly/getting-started

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?