Forums

How to load data into a flask-dtale app (csv file)

Hello I have seen a site working with the dtale library: http://alphatechadmin.pythonanywhere.com/dtale/main/1

But I'm unable to replicate how it works, I can't load a csv file I uploaded to pythonanywhere, I found a forum post saying you need to use the full path in pythonanywhere: /home/USER/mysite/data/ for example

But still I'm unable to figure this out with the documentation example code:

@app.route("/dtale")
def dtalepage():
    mytitle  = "Analysis with dtale library"
    df = pd.read_csv('/home/erikssawa/mysite/data/engine_metadata.csv')
    instance = startup(data=df, ignore_duplicate=True)
    return redirect(f"/dtale/main/{instance._data_id}", code=302)
    # I get the error The requested URL was not found on the server.

My file structure is:

├── flask_app.py

├── static

│---------├── bootstrapfiles, javascript, images dir

├── templates

│---------├──index.html, about.html, dtalepage.html

├── data

│-------├── csv files

full flask_app.py code to copypaste https://pastebin.com/8AL0rR7n

Any help is much appreciated

I think the error is not on the read_csv line, but at the end where you're calling redirect -- make sure that the url is correct.

thank you @pafk, by any chance do you know should I call the redirect statement so I can use the dtale flask app within my flask app ? Many thanks

You'll have to look into the documentation for dtale to find out how it sets up its URLs.