<jupyter_start><jupyter_text>V4A Example 08 - Output FilesThis example shows some things to consider if your notebook generates output files for the user to download.<jupyter_code>import base64
from IPython.display import FileLink<jupyter_output><empty_output><jupyter_text>Create some filesLet's create a python text file and an image of an orange square.<jupyter_code>with open('foo.py', 'w') as f:
    f.write("# hello")
# thanks https://png-pixel.com/
png = '<KEY>'
with open('foo.png', 'wb') as f:
    f.write(base64.b64decode(png))<jupyter_output><empty_output><jupyter_text>FileLinkDon't worry about trying to figure out an absolute URL to link to your files.  If you use a [FileLink](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.htmlIPython.display.FileLink "FileLink documentation") with the same relative path that you used to create the files, then the links will be correct in both Jupyter and Voila.Now, this is where Voila's security comes into play.  By default, `py` files are not allowed to be downloaded.  So this link will work in Jupyter but not in Voila.  In Voila, you'll see a 403 Forbidden error.<jupyter_code>FileLink('foo.py')<jupyter_output><empty_output><jupyter_text>However, `png` files are allowed by default, so this one should work in both Jupyter and Voila.<jupyter_code>FileLink('foo.png')<jupyter_output><empty_output><jupyter_text>Last, another advantage of using FileLink is that it will tell you if you get the filename wrong.<jupyter_code>FileLink('oops.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09389067524115756, 'fraction_numerical': 0.0077170418006430866, 'mean_word_length': 5.946428571428571, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '441663', 'license': 'MIT', 'n_tokens_mistral': 505, 'n_tokens_neox': 490, 'n_words': 171, 'path': 'V4A Example 08 - Output Files.ipynb', 'repo_name': 'nbgallery/Voila4Analysts', 'size': '1682'}