Download from Webapp to Local Downloads

Options
gblack686
gblack686 Partner, Registered Posts: 62 Partner

I need to add a download button in my bokeh webapp to download underlying csv files of charts. My code is below

def export_ml():
ml_path = os.path.join(os.path.expanduser('~'),'downloads')
ml_df.to_csv(export_path + '\'Persistency_Webapp_ML_Data'+timestamp+'.csv', index = False, header=True)
ml_button.on_click(export_ml) 

1. How can I export to my local downloads folder?

2. I notice the os.path.expanduser() directs me to /home/dataiku. How can I access this folder?

Answers

  • Liev
    Liev Dataiker Alumni Posts: 176 ✭✭✭✭✭✭✭✭
    edited July 17
    Options

    Hi @gblack686

    As you've noticed, when the server executes recipes, it has no notion of your machine. You can either:

    - get access to the server, but even then the outputs will likely be inside of tmp folder.

    - use a managed folder to load the file into it.

    folder = dataiku.Folder("YOUR_FOLDER_ID")
    data = ml_df.to_csv(index = False, header=True)
    folder.upload_data('Persistency_Webapp_ML_Data_'+timestamp+'.csv', data)
    

    When the file is inside the managed folder you will be able to download to your machine.

    Hope this helps!

  • gblack686
    gblack686 Partner, Registered Posts: 62 Partner
    edited July 17
    Options

    Hi,

    Yes this is helpful, however I still need a little more help. I've saved the dataset to a managed folder, but now I'm trying to download it with code. (I can't trust that inexperienced users will know how to get to the folder to download, I'd like to make it an instant DL)

    Once I have accessed the file from the folder

    project_key.list_managed_folders()
    folder = project_key.get_managed_folder('kx0VDbs8')
    file_path = folder.list_contents()['items'][0]['path']
    file = folder.get_file(file_path)

    Can I then download this file at that path with code?

    Thanks

  • Liev
    Liev Dataiker Alumni Posts: 176 ✭✭✭✭✭✭✭✭
    Options

    Hi @gblack686

    You can download files from a managed folder by hovering over the files and using the download button.

    Screenshot 2020-09-29 at 09.38.41.png

    Keep in mind that when you execute code in DSS, the context of you users' machines is not there, DSS cannot access the machine in order to put the file in it.

Setup Info
    Tags
      Help me…