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?
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!
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']['path'] file = folder.get_file(file_path)
Can I then download this file at that path with code?
You can download files from a managed folder by hovering over the files and using the download button.
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.