• Skip to main content
  • Skip to primary sidebar

学習記録

Dashのコールバック

2018年9月28日 by 河副 太智 Leave a Comment

Dashのコールバックを使ってテキストフィールドに入力された
値を別の場所にリアルタイムに表示してみます。

 

レイアウトを以下のように設定し、インプットするフォームに
“my-id”と名前を付けます。
また、空のhtmlフィールドを用意して”my-div”と名前を付けます。

1
2
3
4
5
app.layout = html.Div([
    dcc.Input(id="my-id",value="Inisitoa Text",type="text"),
    html.Div(id="my-div")
    
])

 

次にコールバックの設定です。

1
2
3
4
@app.callback(Output(component_id="my-div",component_property="children"),
             [Input(component_id="my-id",component_property="value")])
def updata_output_div(input_value):
    return "You enterd:{}".format(input_value)

Output、つまり出力先は先ほど指定したhtmlの空フィールド”my-div”に
向けているのでテキスト入力フォームの直下にアウトプットされた値が
表示されるという意味になります。

Inputはdcc.Input()で設定した”my-id”から来たものがインプットである
と定義します。

 

このように設定すると表示されたテキストフォームに文字列を
入力すると、フォーム直下の空htmlフィールドに入力した文字列が
即座に反映されます。

 

 

コード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input,Output
 
app = dash.Dash()
 
app.layout = html.Div([
    dcc.Input(id="my-id",value="Inisitoa Text",type="text"),
    html.Div(id="my-div")
    
])
 
@app.callback(Output(component_id="my-div",component_property="children"),
             [Input(component_id="my-id",component_property="value")])
def updata_output_div(input_value):
    return "You enterd:{}".format(input_value)
 
 
if __name__ == '__main__':
    app.run_server()

 

 

このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: Dash

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in