voila-dashboards / voila

Voilà turns Jupyter notebooks into standalone web applications
https://voila.readthedocs.io
Other
5.4k stars 501 forks source link

Unable to download a file #1313

Open vantro opened 1 year ago

vantro commented 1 year ago

Description

A link to an existing file in the current directory is transformed/redirected to /files/ directory. Therefore it can't be accessed or dowloaded

Reproduce

I'm using mybinder.org to load a notebook. In the script I generate a PDF file and I want to download it when finished. As I'm working in the current directory the link provided is my file.

with out:
    display(HTML('<a href="myfile.pdf">my file</a>'))

I have set a voila.json file in witch is defined a whitelist including pdf

But when I click on the link, the url /voila/**render**/myfile.pdf redirects to /voila/**files**/myfile.pdf

What steps should I follow to define the /files directory and to be able to create a file in it, or to avoid a redirection ?

afonit commented 8 months ago

@vantro, I am not familiar with the mybinder scenario, but I know when using voila and to download a file I have needed to do things similar to this:

from io import BytesIO

p2_material_out = widgets.Output()

def material_download_prep(b=None):
    with material_download_link_out:
        button_download_materials.button_style = 'warning'
        button_download_materials.disabled = True
        material_download_link_out.clear_output()
        display(Markdown("""<span style="color:orange">Please wait while the data is retrieved.</span>"""))
        df = structure_material()
    generated_link = create_download_link(
        data_source=df,
        title="Download the data",
        filename='the_data.csv',
    )
    with material_download_link_out:
        material_download_link_out.clear_output()
        display(generated_link)
        button_download_materials.button_style='success'

button_download_materials = widgets.Button(
    description='Generate Data Link'
)

button_download_materials.on_click(material_download_prep)

with material_out:
    material_out.clear_output()
    display(button_download_materials)

Perhaps that might help you.

ggogate commented 8 months ago

Also, the variable name in voila/configuration.py is file_allowlist

Example: --VoilaConfiguration.file_allowlist="['.*\.(png|jpg|gif|svg)', 'public.*']"
vantro commented 8 months ago

Thank you for your answers. Creating a whitelist doesn't solve the problem.

I'm trying to figure out how to configure voila and/or binder to create the /voila/files/ folder so that I can download the files.