Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 126 additions & 87 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import pandas as pd
from dash.dependencies import Input, Output


app = Flask(__name__)
cache = {"filters":""}
cache = {"filters": ""}
df = pd.DataFrame()
available_indicators = df
initial= table.makeTable
initial = table.makeTable
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css', '/static/css/template.css']


#
# server = flask.Flask(__name__)
# plot = dash.Dash(__name__, server=server, url_base_pathname='/get/', external_stylesheets=external_stylesheets)
Expand Down Expand Up @@ -54,7 +55,7 @@ def home():
# print(data)
# return render_template("output.html", colNames=json.dumps(colNames))
if request.method == "GET":
#upon clicking submit this stuff will render
# upon clicking submit this stuff will render
colNames = []
print("from GET!")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Expand All @@ -72,17 +73,48 @@ def home():
tables = initial.outputTable()
df = tables
# cache1 = json.dumps(cache)
colNames = ['choose filter','ABS_wf_D', 'STAT_CC_D', 'STAT_CC_A',
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NOMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']
colNames = ['choose filter', 'ABS_wf_D', 'STAT_CC_D', 'STAT_CC_A',
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NOMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']
print(colNames)

return render_template("output.html", colNames=json.dumps(colNames))
# return render_template("scatter_plot.html", table=[df.to_html(header="true")], tabledata=tabledata)
return render_template("output.html")


@app.route("/data.json")
def data():
jsonfile = initial.returnResponse()
colNames = ['case_name', 'source', 'ABS_wf_D', 'STAT_CC_D', 'STAT_CC_A',
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NOMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']
return render_template("jsondata.html", jsonData=json.dumps(jsonfile), colNames=colNames)


@app.route("/plot")
def plot():
jsonfile = initial.returnResponse()
cols = ['case_name', 'source', 'ABS_wf_D', 'STAT_CC_D', 'STAT_CC_A',
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NORMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']

return render_template("scatter_plot.html", jsonData=jsonfile, colNames=cols)
# table.makeTable.getCache([])
# tables= table.makeTable.outputTable()
# # print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Expand All @@ -92,6 +124,8 @@ def home():
# colNames = json.dumps(cols)
# cache1 = json.dumps('no filters entered yet')
# return render_template("output.html", table=[tables.to_html(header="true")], tabledata=tabledata, colNames=colNames, cache=cache1)


@app.route("/table", methods=["GET"])
def table():
global cache
Expand All @@ -111,9 +145,9 @@ def table():
# print(df)
# tabledata = json.dumps(initial.getBoolData())
# return render_template("index.html", table=[df.to_html(header="true")], tabledata=tabledata)
if request.method=="GET":
#have filters in the URL that GET can access
#request.args.GET
if request.method == "GET":
# have filters in the URL that GET can access
# request.args.GET
print("~~~~~~~~~~~~~~~GOT GET~~~~~~~~~~~~~~~~~~~~~")
# print(request.args)
# data = request.args
Expand All @@ -126,14 +160,16 @@ def table():
initial.getCache(cache["filters"])
tables = initial.outputTable()
df = tables
print(df)
print(f"tables {df}")
tabledata = json.dumps(initial.getBoolData())
print(tabledata)
# return render_template("scatter_plot.html", table=[df.to_html(header="true")], tabledata=tabledata)
return render_template("index.html", table=[df.to_html(header="true")], tabledata=tabledata)
return render_template("index.html", table=[df.to_html(header="true")], tabledata=tabledata)
#serve this as iframe???
# serve this as iframe???

@app.route("/export", methods=["GET"]) # this is a job for GET, not POST

@app.route("/export", methods=["GET"]) # this is a job for GET, not POST
def export():
print("export clicekd???")
df.to_csv("output/datafile.csv")
Expand All @@ -142,93 +178,96 @@ def export():
attachment_filename='datafile.csv',
as_attachment=True)

plot = dash.Dash(__name__, server=app, url_base_pathname='/dash/',external_stylesheets=external_stylesheets)

plot = dash.Dash(__name__, server=app, url_base_pathname='/dash/', external_stylesheets=external_stylesheets)

colNames = ['ABS_wf_D', 'STAT_CC_D', 'STAT_CC_A',
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NOMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']
'STAT_CC_D_An', 'STAT_CC_A_Ca', 'STAT_n', 'STAT_n_D', 'STAT_n_A',
'ABS_f_D', 'CT_f_conn_D', 'CT_f_conn_D_An', 'CT_f_conn_A_Ca',
'DISS_wf10_D', 'DISS_f10_D', 'DISS_f2_D', 'DISS_prob_reach_I', 'STAT_e',
'CT_e_conn', 'CT_f_e_conn', 'CT_e_D_An', 'CT_e_A_Ca', 'CT_n_D_adj_An',
'CT_f_D_tort1', 'CT_wtort_D', 'CT_n_A_adj_Ca', 'CT_f_A_tort1',
'CT_wtort_A', 'int_x', 'int_d', 'int_g', 'int_r', 'NOMALIZED_INTERFACE',
'jsc', 'jsc_d', 'int_r_int_d', 'int_d_int_g', 'jsc_int_d']
plot.layout = html.Div([
# dcc.Interval(id='dash-table', interval=10000),
html.Div([
html.Div([
dcc.Dropdown(
id='xaxis-column',
options=[{'label': i, 'value': i} for i in colNames],
value='int_r'
),
dcc.RadioItems(
id='xaxis-type',
options=[{'label': i, 'value': i} for i in ['Linear', 'Log']],
value='Linear',
labelStyle={'display': 'inline-block'}
)
],style={'width': '48%', 'display': 'inline-block'}),

html.Div([
dcc.Dropdown(
# dcc.Interval(id='dash-table', interval=10000),
html.Div([
html.Div([
dcc.Dropdown(
id='xaxis-column',
options=[{'label': i, 'value': i} for i in colNames],
value='int_r'
),
dcc.RadioItems(
id='xaxis-type',
options=[{'label': i, 'value': i} for i in ['Linear', 'Log']],
value='Linear',
labelStyle={'display': 'inline-block'}
)
], style={'width': '48%', 'display': 'inline-block'}),

html.Div([
dcc.Dropdown(
id='yaxis-column',
options=[{'label': i, 'value': i} for i in colNames],
value='STAT_n_A'
),
dcc.RadioItems(
id='yaxis-type',
options=[{'label': i, 'value': i} for i in ['Linear', 'Log']],
value='Linear',
labelStyle={'display': 'inline-block'}
)
],style={'width': '48%', 'float': 'right', 'display': 'inline-block'})
dcc.RadioItems(
id='yaxis-type',
options=[{'label': i, 'value': i} for i in ['Linear', 'Log']],
value='Linear',
labelStyle={'display': 'inline-block'}
)
], style={'width': '48%', 'float': 'right', 'display': 'inline-block'})
]),

dcc.Graph(id='indicator-graphic'),
dcc.Graph(id='indicator-graphic'),

])


@plot.callback(
Output('indicator-graphic', 'figure'),
[Input('xaxis-column', 'value'),
Input('yaxis-column', 'value'),
Input('xaxis-type', 'value'),
Input('yaxis-type', 'value')])
Input('yaxis-column', 'value'),
Input('xaxis-type', 'value'),
Input('yaxis-type', 'value')])
def update_graph(xaxis_column_name, yaxis_column_name,
xaxis_type, yaxis_type):
dff = df
print("whyyyyyyyyyyyyyyyyyy")
print(dff.columns)
return {
'data': [dict(
x=dff[xaxis_column_name],
y=dff[yaxis_column_name],
text=dff['STAT_n_A'] ,
mode='markers',
marker={
'size': 15,
'opacity': 0.5,
'line': {'width': 0.5, 'color': 'white'}
}
)],
'layout': dict(
xaxis={
'title': xaxis_column_name,
#'type': 'linear'
'type': 'linear' if xaxis_type == 'Linear' else 'log'
},
yaxis={
'title': yaxis_column_name,
#'type': 'linear'
'type': 'linear' if yaxis_type == 'Linear' else 'log'
},
margin={'l': 40, 'b': 40, 't': 10, 'r': 0},
hovermode='closest'
)
}
xaxis_type, yaxis_type):
dff = df
print("whyyyyyyyyyyyyyyyyyy")
print(dff.columns)
print(f"x: {xaxis_column_name}, y: {yaxis_column_name}")
return {
'data': [dict(
x=dff[xaxis_column_name],
y=dff[yaxis_column_name],
text=dff['STAT_n_A'],
mode='markers',
marker={
'size': 15,
'opacity': 0.5,
'line': {'width': 0.5, 'color': 'white'}
}
)],
'layout': dict(
xaxis={
'title': xaxis_column_name,
# 'type': 'linear'
'type': 'linear' if xaxis_type == 'Linear' else 'log'
},
yaxis={
'title': yaxis_column_name,
# 'type': 'linear'
'type': 'linear' if yaxis_type == 'Linear' else 'log'
},
margin={'l': 40, 'b': 40, 't': 10, 'r': 0},
hovermode='closest'
)
}


if __name__ == "__main__":
#app.run(host="localhost", port=3050, debug=True)
# app.run(host="localhost", port=3050, debug=True)
plot.run_server(host="localhost", port=3050, threaded=True, debug=True)
# plot.run_server(host="localhost", port=2000, debug=True)
50 changes: 49 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,56 @@
{% endfor %}
<!-- <iframe id="dash-table" src="http://localhost:8050" width=700 height=300></iframe> -->
</div>

</body>

<!-- <script>
//import {chart as chart1} with {values as data} from "@d3/histogram"
// set the dimensions and margins of the graph
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 460 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
var JSONData = $("#jsondata");

// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");

//Read the data
d3.json(JSONData, function(data) {
// Add X axis
var x = d3.scaleLinear()
.domain([0, 4000])
.range([ 0, width ]);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));

// Add Y axis
var y = d3.scaleLinear()
.domain([0, 5000])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));

// Add dots
svg.append('g')
.selectAll("dot")
.data(data)
.enter()
.append("circle")
.attr("cx", function (d) { return x(d.GrLivArea); } )
.attr("cy", function (d) { return y(d.SalePrice); } )
.attr("r", 1.5)
.style("fill", "#69b3a2")
});

</script> -->

<!-- <script type="text/javascript">
$(function(){
var filters = $("#filters");
Expand Down
21 changes: 21 additions & 0 deletions templates/jsondata.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jsonData</title>
</head>
<body>
<div id="data-viz">
{{ jsonData | safe }}
</div>
<script>
var element ={{ jsonData | tojson| safe }};
var json = JSON.parse(element);

var a = {{ colNames | safe }}
var firstElem = a[0];

//var colNames = document.getElementById("colNames");
</script>
</body>
</html>
Loading