public
Last active

  • Download Gist
bottle_cohort_analysis.py
Python
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
import os
from bottle import run, template, get, post, request
from plotly import plotly
 
py = plotly(username='mjhea0', key='2ic27cpzex')
 
@get('/plot')
def form():
return '''<h2>Graph via Plot.ly</h2>
<form method="POST" action="/plot">
<table>
<tr>
<td>
<h3><center>2009</center></h3>
Cohort 0: <input name="Y01" type="number"/><br/>
Cohort 1: <input name="Y02" type="number"/><br/>
Cohort 2: <input name="Y03" type="number"/><br/>
Cohort 3: <input name="Y04" type="number"/><br/>
</td>
<td>
<h3>2010</h3>
<input name="Y11" type="number"/><br/>
<input name="Y12" type="number"/><br/>
<input name="Y13" type="number"/><br/>
<input name="Y14" type="number"/><br/>
</td>
<td>
<h3>2011</h3>
<input name="Y21" type="number"/><br/>
<input name="Y22" type="number"/><br/>
<input name="Y23" type="number"/><br/>
<input name="Y24" type="number"/><br/>
</td>
<td>
<h3>2012</h3>
<input name="Y31" type="number"/><br/>
<input name="Y32" type="number"/><br/>
<input name="Y33" type="number"/><br/>
<input name="Y34" type="number"/><br/>
</td>
<td>
</td>
</tr>
</table>
<input type="submit"/>
</form>'''
 
@post('/plot')
def submit():
Y01 = request.forms.get('Y01')
Y02 = request.forms.get('Y02')
Y03 = request.forms.get('Y03')
Y04 = request.forms.get('Y04')
 
Y11 = request.forms.get('Y11')
Y12 = request.forms.get('Y12')
Y13 = request.forms.get('Y13')
Y14 = request.forms.get('Y14')
 
Y21 = request.forms.get('Y21')
Y22 = request.forms.get('Y22')
Y23 = request.forms.get('Y23')
Y24 = request.forms.get('Y24')
 
Y31 = request.forms.get('Y31')
Y32 = request.forms.get('Y32')
Y33 = request.forms.get('Y33')
Y34 = request.forms.get('Y34')
 
x0 = [2010,2011,2012]; y0 = [Y01,Y02,Y03,Y04]
x1 = [2010,2011,2012]; y1 = [Y11,Y12,Y13,Y14]
x2 = [2010,2011,2012]; y2 = [Y21,Y22,Y23,Y24]
x3 = [2010,2011,2012]; y3 = [Y31,Y32,Y33,Y34]
response = py.plot(x0, y0, x1, y1, x2, y2, x3, y3)
url = response['url']
filename = response['filename']
return template('''Congrats! View your chart here <a href="{{url}}">{{url}}</a>!''', url=url)
 
if __name__ == '__main__':
port = int(os.environ.get('PORT', 8080))
run(host='0.0.0.0', port=port, debug=True)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.