Letting app users download files
A common use case for apps is preparing some results as a CSV file, and letting the end user download it. Here's a short guide how to do that.
Let's generate a DataFrame
10 / 100
The results are ready!
When you publish your project as app, you can access the contents of the filesystem using a URL of this format:
https://deepnote.com/publish/<project_id>/file?path=<file_path>
You can find the project_id in the URL, it's in the form of UUID. The general structure of the URL when editing a notebook is
https://deepnote.com/workspace/<workspace_name>-<workspace_id>/project/<project_name>-<project_id>/notebook/<notebook_name>-<notebook_id>
You can also find it in an environment variable DEEPNOTE_PROJECT_ID
For example, the URL to access results.csv in this project is this:
Additional notes
The access controls of the published app are still respected – only people with access to the app can access the files. Note: all files in the /work directory (what you see in the left sidebar) can be accessed this way, so make sure you are not exposing anything sensitive.
Keep in mind that parallel executions of the app (two users at the same time) could overwrite each other's files. If that is a concern, consider generating unique filenames at execution time, and printing the generated URL for each user.