Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dd6295f

Browse files
first commit
0 parents commit dd6295f

File tree

24 files changed

+1461
-0
lines changed

24 files changed

+1461
-0
lines changed

‎.gitignore‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env
2+
.DS_Store
3+
__pycache__
4+
.ropeproject
5+
.idea
6+
data
7+
.webassets-cache

‎Pipfile‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
python-dotenv="*"
8+
9+
[packages]
10+
flask="*"
11+
flask_assets="*"
12+
flask_redis="*"
13+
flask_sqlalchemy="*"
14+
pathlib="*"
15+
dash="*"
16+
dash_core_components="*"
17+
dash_html_components="*"
18+
dash-renderer="*"
19+
pandas="*"
20+
lesscpy="*"
21+
psycopg2-binary="*"
22+
cssmin="*"
23+
jsmin="*"
24+
25+
26+
[requires]
27+
python_version = "3.7"

‎Pipfile.lock‎

Lines changed: 416 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# plotlydash-flask-tutorial

‎config.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
4+
class Config:
5+
"""Global configuration variables."""
6+
7+
# General Config
8+
SECRET_KEY = os.environ.get('SECRET_KEY')
9+
FLASK_APP = os.environ.get('FLASK_APP')
10+
FLASK_ENV = os.environ.get('FLASK_ENV')
11+
12+
# Assets
13+
LESS_BIN = os.environ.get('LESS_BIN')
14+
ASSETS_DEBUG = os.environ.get('ASSETS_DEBUG')
15+
LESS_RUN_IN_DEBUG = os.environ.get('LESS_RUN_IN_DEBUG')
16+
17+
# Static Assets
18+
STATIC_FOLDER = os.environ.get('STATIC_FOLDER')
19+
TEMPLATES_FOLDER = os.environ.get('TEMPLATES_FOLDER')
20+
COMPRESSOR_DEBUG = os.environ.get('COMPRESSOR_DEBUG')

‎plotly_flask_tutorial/__init__.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from flask import Flask
2+
from . import plotly_dash_views
3+
4+
5+
def create_app():
6+
"""Construct the core application."""
7+
app = Flask(__name__, instance_relative_config=False)
8+
app.config.from_object('config.Config')
9+
dash_app = plotly_dash_views.dataframes.Add_Dash(app)
10+
11+
with app.app_context():
12+
13+
# Construct the data set
14+
from . import routes
15+
app.register_blueprint(routes.main_bp)
16+
# app.register_blueprint(plotly_dash_views.routes.plotly_bp)
17+
18+
return app
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pkgutil
2+
3+
__version__ = '0.1.0'
4+
5+
__all__ = []
6+
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
7+
__all__.append(module_name)
8+
_module = loader.find_module(module_name).load_module(module_name)
9+
globals()[module_name] = _module
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import glob
2+
from pathlib import Path, PurePath
3+
from dash import Dash
4+
import dash_table
5+
import dash_core_components as dcc
6+
import dash_html_components as html
7+
import pandas as pd
8+
9+
p = Path('.')
10+
11+
12+
def Add_Dash(server):
13+
"""Populates page with previews of datasets."""
14+
external_stylesheets = ['https://hackers.nyc3.cdn.digitaloceanspaces.com/css/plotly-flask-tutorial8.css',
15+
'https://fonts.googleapis.com/css?family=Lato',
16+
'https://use.fontawesome.com/releases/v5.8.1/css/all.css']
17+
dash_app = Dash(server=server,
18+
url_base_pathname='/plotly_dash_views/',
19+
external_stylesheets=external_stylesheets)
20+
dash_app.index_string = '''<!DOCTYPE html>
21+
<html>
22+
<head>
23+
{%metas%}
24+
<title>{%title%}</title>
25+
{%favicon%}
26+
{%css%}
27+
</head>
28+
<body>
29+
<nav>
30+
<a href="/"><i class="fas fa-home"></i> Home</a>
31+
<a href="/plotly_dash_views/"><i class="fas fa-chart-line"></i> Embdedded Plotly Dash</a>
32+
</nav>
33+
{%app_entry%}
34+
<footer>
35+
{%config%}
36+
{%scripts%}
37+
{%renderer%}
38+
</footer>
39+
</body>
40+
</html>'''
41+
42+
43+
# Create layout
44+
dash_app.layout = html.Div(
45+
children=get_datasets(),
46+
id='flex-container'
47+
)
48+
49+
return dash_app.server
50+
51+
52+
def get_datasets():
53+
"""Gets all CSVs in /data directory."""
54+
data_filepath = list(p.glob('plotly_flask_tutorial/plotly_dash_views/data/*.csv'))
55+
arr = ['This is an example Plot.ly Dash App.']
56+
for index, csv in enumerate(data_filepath):
57+
print(PurePath(csv))
58+
df = pd.read_csv(data_filepath[index]).head(10)
59+
table_preview = dash_table.DataTable(
60+
id='table_' + str(index),
61+
columns=[{"name": i, "id": i} for i in df.columns],
62+
data=df.to_dict("rows"),
63+
sorting=True,
64+
)
65+
arr.append(table_preview)
66+
return arr
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<title>{{title}}</title>
7+
<meta name="HandheldFriendly" content="True" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
9+
<script src="{{ url_for('static', filename='dist/js/includes/jquery.min.js') }}"></script>
10+
<link rel="stylesheet" href="{{ url_for('static', filename='dist/css/main.min.css') }}">
11+
<link rel="shortcut icon" href="{{ url_for('static', filename='dist/img/favicon.png') }}" type="image/x-icon" />
12+
</head>
13+
<body class="{{template}}">
14+
<div class="container">
15+
{{body}}
16+
</div>
17+
</body>
18+
19+
</html>

‎plotly_flask_tutorial/routes.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
from flask import Blueprint, render_template
3+
from flask_assets import Environment, Bundle
4+
from flask import current_app as app
5+
import lesscpy
6+
7+
main_bp = Blueprint('main_bp', __name__,
8+
template_folder='templates',
9+
static_folder='static')
10+
assets = Environment(app)
11+
Environment.auto_build = True
12+
Environment.debug = False
13+
less_bundle = Bundle('less/*.less',
14+
filters='less,cssmin',
15+
output='dist/css/style.css',
16+
extra={'rel': 'stylesheet/less'})
17+
js_bundle = Bundle('js/*.js',
18+
filters='jsmin',
19+
output='dist/js/main.js')
20+
assets.register('less_all', less_bundle)
21+
assets.register('js_all', js_bundle)
22+
# less_bundle.build(force=True)
23+
js_bundle.build()
24+
25+
26+
# Landing Page
27+
@main_bp.route('/', methods=['GET'])
28+
def home():
29+
return render_template('index.html',
30+
title='Plotly Flask Tutorial.',
31+
template='home-template',
32+
body="This is an example homepage, served with Flask.")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /