fix: ensure plotly backend is set in result_view and custom routes

- Add pd.options.plotting.backend = 'plotly' at route level
- Fixes matplotlib ImportError in Railway deployment
- Ensures DataFrame.plot() uses plotly instead of matplotlib
- Resolves Internal Server Error on result_view pages
master
Eric0801 2 months ago
parent e75773733c
commit 4956bdca5f
  1. 8
      main.py

@ -415,6 +415,10 @@ def custom_post():
else: else:
flash('使用投組功能請先登入。', 'warning') flash('使用投組功能請先登入。', 'warning')
return redirect(url_for('login')) return redirect(url_for('login'))
# Ensure plotly backend is set
pd.options.plotting.backend = "plotly"
port = pd.read_csv(request.files['csv_file'], index_col=0, parse_dates=True) port = pd.read_csv(request.files['csv_file'], index_col=0, parse_dates=True)
role = request.form.get('role') role = request.form.get('role')
lookback = int(request.form.get('lookback')) lookback = int(request.form.get('lookback'))
@ -538,6 +542,10 @@ def result_view():
else: else:
sid = request.args.get('strategy_id') sid = request.args.get('strategy_id')
strategy_id = request.args.get('strategy_id') strategy_id = request.args.get('strategy_id')
# Ensure plotly backend is set (fixes Railway deployment issue)
pd.options.plotting.backend = "plotly"
sql="""select * from strategy where id=%s;""" sql="""select * from strategy where id=%s;"""
conn = psycopg2.connect(**SQL_CONFIG) conn = psycopg2.connect(**SQL_CONFIG)
with conn: with conn:

Loading…
Cancel
Save