Upgrade to Pro — share decks privately, control downloads, hide ads and more …

dash-handson

Hide Ogawa
November 18, 2018

 dash-handson

dash hands on / Hannari Python #11 2018 / 11/ 16

Hide Ogawa

November 18, 2018
Tweet

More Decks by Hide Ogawa

Other Decks in Technology

Transcript

  1. DASH HANDS ON はんなりPYTHON #11 Navigate : Space / Arrow

    Keys | - Menu | - Fullscreen | - Overview | - Blackout | - Speaker | - Help M F O B S ?  1 / 20
  2. CUIで [ $python app1.py ] とすると・・・ # -*- coding: utf-8

    -*- import dash import dash_core_components as dcc import dash_html_components as html app = dash.Dash() app.layout = html.Div(children=[ html.H1(children='Hello Dash'), html.Div(children=''' Dash: A web application framework for Python. '''), dcc Graph( [ GitPitch @ github/hannari-python/dash-handson ]  6 / 20
  3. app = dash.Dash() / アプリの箱作り app.layout = ~~~ / アプリの中身作り

    / インタラクティブなイン ターフェースを作る。スライダーとかボタン、グラ フもこれを使う。 / アプリケーションの HTMLの部分に使う。 / 11月2日にリリースされた。データを 見るのに良い塩梅にしてくれる。 dash_core_components dash_html_components dash_table [ GitPitch @ github/hannari-python/dash-handson ]  8 / 20
  4. sliderから年をインプット ==> その年で関数実行 ==> 関数内のgo.scatterで作図 ==> dcc.Graphに それを渡す(app4.py) import dash

    import dash_core_components as dcc import dash_html_components as html import pandas as pd import plotly.graph_objs as go df = pd.read_csv( 'fiveyeardata.csv') external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.c app = dash.Dash(__name__, external_stylesheets=external_styleshee app.layout = html.Div([ dcc.Graph(id='graph-with-slider'), dcc Slider( [ GitPitch @ github/hannari-python/dash-handson ]  12 / 20
  5. 3つのコールバックにより、複雑な動きを実現して いる。(app5.py) 右の二つのチャートはdef create_time_series()で 作られている。 import dash import dash_core_components as

    dcc import dash_html_components as html import pandas as pd import plotly.graph_objs as go external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.c app = dash.Dash(__name__, external_stylesheets=external_styleshee df = pd.read_csv('indicators.csv') available_indicators = df['Indicator Name'].unique() app.layout = html.Div([ html Div([ [ GitPitch @ github/hannari-python/dash-handson ]  13 / 20
  6. すごいー 解説はなしの方向で・・・(app6.py) import dash from dash.dependencies import Input, Output import

    dash_html_components as html import dash_core_components as dcc import pandas as pd import flask from flask_cors import CORS import os app = dash.Dash('drug-discovery') server = app.server df = pd.read_csv('small_molecule_drugbank.csv').drop(['Unnamed: 0 if 'DYNO' in os.environ: app scripts append script({ [ GitPitch @ github/hannari-python/dash-handson ]  14 / 20
  7. グラフを下にどんどん足している。(app7.py) import dash import dash_core_components as dcc import dash_html_components as

    html import datetime as dt import flask import os import pandas as pd import time app = dash.Dash( __name__, assets_external_scripts='https://cdn.plot.ly/plotly-finance-1 ) server = app.server [ GitPitch @ github/hannari-python/dash-handson ]  15 / 20