본문 바로가기

Flask

[Flask] flask web에서 plotly.figure_factory 연결

app.py 파일

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, render_template
import plotly.figure_factory as ff
import plotly
import json
 
import numpy as np
import pandas as pd
 
app = Flask(__name__)
 
# @는 밑에 def를 바로 실행시킴
def index():
 
#그래프를 받아서 index.html에 띄우기
    bar = create_gantt()
    return render_template('index.html', plot=bar)
 
 
def create_gantt():
 
#엑셀 데이터 read
    process_product = pd.read_excel(
        'data/Factory_revision.xlsx', encoding='utf-8')
 
#간트차트 생성
    fig = ff.create_gantt(
        process_product, index_col='Resource'
        title='Process by products', group_tasks=True,
        show_colorbar=True, bar_width=0.2, showgrid_x=True, showgrid_y=True)
 
#그래프 json으로 넘겨주기
    return graphJSON
 
#단독으로 파이썬 명령이 들어왔을때만 포트 실행
if __name__ == '__main__':
    app.run(debug=True)
#개발할 때 항상 debug mode를 ON으로 하기!
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html>
  <head>
    <title>Flask Template Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
media="screen">
    <style type="text/css">
      .container {
        max-width: 500px;
        padding-top: 100px;
      }
    </style>
  </head>
  <body>
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    <div class="chart" id="bargraph">
    <script>
        var graphs = {{plot | safe}};
        Plotly.plot('bargraph',graphs,{});
    </script>
    </div>  
    <p>create by EUN on 2020.03.05</p>
</body>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

Reference Sites

https://blog.heptanalytics.com/flask-plotly-dashboard/

 

Flask + Plotly Dashboard – Hepta Analytics Blog

Last week I had 3 days to come up with a visualization dashboard. My backend choice was flask (we are inseparable) however I had to choose the easiest plotting package. The choices that I had was between plotly, dash and bokeh. Looking at the bokeh documen

blog.heptanalytics.com

https://community.plot.ly/t/plotly-doesnt-load-most-of-the-time/32095/12

 

Plotly doesn't load most of the time

I ended up embedding the plotly code into a flask app. That works flawlessly. Thanks for your help! Here’s an example if anyone wants to do the same: app.py: from flask import Flask, render_template import plotly.figure_factory as ff import plotly import j

community.plot.ly

 

 

+++추후 프로젝트 방향

https://ssoonidev.tistory.com/71

https://kkamikoon.tistory.com/162

 

'Flask' 카테고리의 다른 글

[flask-mysql] 설치오류  (0) 2020.05.12