samedi 1 février 2020

How can I send data several times by spliting to client, using python flask?

I have a big-data that type of 'csv' file. (about 50,000 rows) I typed the code to send the big-data from python flask server and display that at web-page.

I want to send big-data several times by spliting to client(100rows × 500times) with progress bar.
How can I implement?
(I think, there are two methods; 1st server side Python code, 2nd client side JS code. I want to all of methods.)

Below, I share my simple code that data can be interacted between server and client.
(When client click 'data load' button, server send just one time request all data.)
Referencing this below basic code, please give me advice.

thank you.



[Server-side : python code]

from flask import Flask, render_template, request, jsonify;

app = Flask(__name__)
@app.route('/', methods=['GET','POST'])
def clipboard():
    if request.method == 'POST':
        data = pd.read_csv('bigDataFile.csv', engine='python', encoding='ms949').to_dict('record')
        # 'bigDataFile.csv' have 50,000 rows data
        return jsonify(result=data), 201;
    if request.method == 'GET':
        return render_template('index.html')

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000,  debug=True);

[Client-Side : html, js code]

<!-- index.html -->
<body>
    <button type="submit" id="loadData">Data Load</button>
    <div class="container">
        <div id="DataDisplay"></div> <!-- show requested data at this-->
    </div>

    <script>
        $('button#loadData').bind('click', ()=>{
            $.ajax({
            url: '/',
            contentType: 'application/json',
            method: 'POST',
        })
        .done(data => {
            let getData = data;
            document.querySelector('#DataDisplay').innerHTML = data;
        })
    </script>
</body>



Aucun commentaire:

Enregistrer un commentaire