๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

Dash์™€ Python์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑ ๋ณธ๋ฌธ

๐Ÿ‘ฉ‍๐Ÿ’ป ์ธ๊ณต์ง€๋Šฅ (ML & DL)/Serial Data

Dash์™€ Python์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ ๊ทธ๋ž˜ํ”„๋ฅผ ์ƒ์„ฑ

์ง•์ง•์•ŒํŒŒ์นด 2022. 11. 14. 13:15
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” pythonprogramming_net ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค>

https://pythonprogramming.net/live-graphs-data-visualization-application-dash-python-tutorial/

 

Python Programming Tutorials

Live Graphs - Data Visualization GUIs with Dash and Python p.4 Welcome to part four of the web-based data visualization with Dash tutorial series. In this tutorial, we're going to be create live updating graphs with Dash and Python. Live graphs can be usef

pythonprogramming.net

 

 

๐Ÿ”” Dash ๊ธฐ๋ณธ ๊ตฌ์กฐ

  • dash lib, ๋‹ค์–‘ํ•œ ๊ตฌ์„ฑ ์š”์†Œ(๊ทธ๋ž˜ํ”„ ๊ตฌ์„ฑ ์š”์†Œ์™€ ๊ฐ™์€ ๊ฒƒ), HTML ๊ตฌ์„ฑ ์š”์†Œ(div ํƒœ๊ทธ ๋“ฑ...๋“ฑ)์™€ ๊ฐ™์€ ๊ฒƒ์„ ๊ฐ€์ ธ์˜ด
  • Dash๋Š” Flaskํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ๊ตฌ์ถ•
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div('Dash Tutorials')
if __name__ == '__main__':
    app.run_server(debug=True)

 

 

๐Ÿ”” ์‹ค์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ ๊ทธ๋ž˜ํ”„

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque

X = deque(maxlen=20)
X.append(1)
Y = deque(maxlen=20)
Y.append(1)

# ์ž„์˜์˜ ์›€์ง์ž„์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๋ฅผ ์‹œ๋ฎฌ๋ ˆ์ด์…˜
app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Graph(id='live-graph', animate=True),
        dcc.Interval(
            id='graph-update',
            interval=1*1000
        ),
    ]
)

# ์ž„์˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€
@app.callback(Output('live-graph', 'figure'),
              [Input('graph-update', 'n_intervals')])

def update_graph_scatter(input_data):
    X.append(X[-1]+1)
    Y.append(Y[-1]+Y[-1]*random.uniform(-0.1,0.1))

    # ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋  ๋•Œ๋งˆ๋‹ค ๋ช‡ ๊ฐ€์ง€ ์ƒˆ๋กœ์šด ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์œผ๋ฏ€๋กœ ๊ณ„์†ํ•ด์„œ ๊ทธ๋ž˜ํ”„๋ฅผ ์ž‘์„ฑํ•˜๋ ค๊ณ  ํ•จ
    data = plotly.graph_objs.Scatter(
            x=list(X),
            y=list(Y),
            name='Scatter',
            mode= 'lines+markers'
            )

    # x์™€ y์— ๋Œ€ํ•œ ๋ชฉ๋ก์„ ์ „๋‹ฌํ•ด์•ผ ํ•˜๋ฏ€๋กœ deque๊ฐœ์ฒด๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์—†์Œ
    return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),
                                                yaxis=dict(range=[min(Y),max(Y)]),)}

if __name__ == '__main__':
    app.run_server(host='0.0.0.0', port=8080 ,debug=True)

 

๊ฐ’์ด ๋ˆ„์ ๋˜์ง€ ์•Š์Œ

728x90
๋ฐ˜์‘ํ˜•
Comments