From 4956bdca5fc39ebd0e2074b6cbfaa7103824ce78 Mon Sep 17 00:00:00 2001 From: Eric0801 <33929918+Eric0801@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:56:43 +0800 Subject: [PATCH] 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 --- main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.py b/main.py index 7ed1e04..9f72d18 100644 --- a/main.py +++ b/main.py @@ -415,6 +415,10 @@ def custom_post(): else: flash('使用投組功能請先登入。', 'warning') 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) role = request.form.get('role') lookback = int(request.form.get('lookback')) @@ -538,6 +542,10 @@ def result_view(): else: sid = 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;""" conn = psycopg2.connect(**SQL_CONFIG) with conn: