嗨,我正在使用 Python、Bottle 生成图表。但是,这会返回一个 url。喜欢:
https://plot.ly/~abhishek.mitra.963/1
我想将整个图表粘贴到我的网页中,而不是提供链接。这可能吗?
我的代码是:
import os
from bottle import run, template, get, post, request
from plotly import plotly
py = plotly(username='user', key='key')
@get('/plot')
def form():
return '''<h2>Graph via Plot.ly</h2>
<form method="POST" action="/plot">
Name: <input name="name1" type="text" />
Age: <input name="age1" type="text" /><br/>
Name: <input name="name2" type="text" />
Age: <input name="age2" type="text" /><br/>
Name: <input name="name3" type="text" />
Age: <input name="age3" type="text" /><br/>
<input type="submit" />
</form>'''
@post('/plot')
def submit():
name1 = request.forms.get('name1')
age1 = request.forms.get('age1')
name2 = request.forms.get('name2')
age2 = request.forms.get('age2')
name3 = request.forms.get('name3')
age3 = request.forms.get('age3')
x0 = [name1, name2, name3];
y0 = [age1, age2, age3];
data = {'x': x0, 'y': y0, 'type': 'bar'}
response = py.plot([data])
url = response['url']
filename = response['filename']
return ('''Congrats! View your chart here <a href="https://plot.ly/~abhishek.mitra.963/1">View Graph</a>!''')
if __name__ == '__main__':
port = int(os.environ.get('PORT', 8080))
run(host='0.0.0.0', port=port, debug=True)