无法更新heroku中的散景图

问题描述 投票:0回答:1

我正在创建一个带有散景图的Heroku应用程序,可以使用用户输入进行更新。当我运行我的python代码时,我看到这些图在我的本地目录中更新,但在Heroku应用程序上没有任何变化。这是我的app.py的相对部分:

def graph(sym,yr,month):
    response=requests.get(some_link)
    data=response.json()
    df=pd.DataFrame(data)
    p = figure(plot_width=600, plot_height=400)
    x_axis=[i for i in range(len(df.values))]
    p.line(x_axis,df['4. close'].iloc[::-1], line_width=2)
    output_file('templates\image.html')
    save(p)

app = Flask(__name__)

@app.route('/')
def index_lulu():
    return render_template('stockticker.html')

@app.route('/static/<path:path>',methods=['GET','POST'])
def static_file(path):
    return app.send_static_file(os.path.join('static', path))

@app.route('/image.html',methods=['GET','POST'])
    def hello3():
    symbol=request.form['symbol_lulu']
    year=request.form['year_lulu']
    month=request.form['month_lulu']
    graph(symbol,year,month)
    return render_template('image.html')

if __name__ == "__main__":
    app.run(debug=False)

stockticker.html接受符号,年,月的输入。当我在终端上运行app.py时,image.html会不断更新,但是当我在Heroku上部署它时,它总是会显示相同的情节。我对这个领域很新,任何帮助都会受到赞赏。谢谢!

heroku flask bokeh
1个回答
0
投票

您的直接问题很可能与您正在使用的路径名称相关。检查您的日志,看看那里是否有任何有趣的错误消息。

但即使你得到了它的工作,它可能不会做你期望的。 Heroku的文件系统is ephemeral。您对dyno重新启动时所做的任何更改都将丢失,即happens frequently(每天至少一次)。您无法将文件保存到文件系统并期望它们保留在那里。

Heroku的official recommendation是我们的第三方服务,如Amazon S3,用于存储用户上传,动态生成的文件等。这也是常规静态文件的好地方。

(在这种情况下,由于您每次加载视图时都在创建文件,因此您可能能够使其正常工作。但是将生成的图像缓存一段时间可能更有效,而且您不能这样做在Heroku的文件系统上可靠的。)

© www.soinside.com 2019 - 2024. All rights reserved.