API Docs
OutputDir

OutputDir

Use OutputDir when you would like to save files for download.

import os
import mercury as mr
# get output directory widget
# all files saved in the OutputDir will be available for download in Mercury
my_dir = mr.OutputDir()
# print output directory path
print(f"All files will be saved to {my_dir.path}")
 
# save example file
with open(os.path.join(my_dir.path, "example-file.txt"), "w") as fout:
    fout.write("Hello Mercury!")
 
# the file `example-file.txt` will be available for download in the Mercury app.

When running notebook as web app, there will be an additional view Output Files. It will list all files saved in the OutputDir.

Example Mercury App with OutputDir widget and output file

The OutputDir creates temporary directory where files are saved. You can't save directories in the OutputDir, only files.

There should be only one instance of OutputDir in the notebook.

If you will create several instances of OutputDir they will point to the same path.

Example App

Here is a simple Python notebook that creates two text files in the OutputDir. (You can save files in the any format in the OutputDir.)

Python notebook with OutputDir

Preview of Output Files in the Mercury:

Mercury App with OutputDir widget with output files