How to show dataframe table from Flask in JScrollPane

Viewed 8

Firstly, I use python Flask to return a dataframe:

@app.route('/')
def predict():
    # this part will be replaced by the prediction result of a model, e.g. SVC
    test_file = "../Data/test.csv"
    df = pd.read_csv(test_file).iloc[:, 2:9]
    return df.to_html(classes="table table-striped",index=False)
return df.to_html(classes="table table-striped",index=False)

Then, I want to show the table in JScrollPane in my Java program:

if(ae.getSource() == predictButton)
{
            try {
            URL url = new URL("http://127.0.0.1:5000/");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");
            
            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + conn.getResponseCode());
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(
                     (conn.getInputStream())));
            //tableScrollPane.setViewportView(br);???? it does not work
            conn.disconnect();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }catch (IOException e){
                e.printStackTrace();
            }
}

After pressing the "predictButton", JscrollPane should show the table from Flask. Any help would be appreciated!

0 Answers
Related