holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.75k stars 517 forks source link

Filedownload callback doesnt work with auto=False #1471

Open Jhsmit opened 4 years ago

Jhsmit commented 4 years ago

ALL software version info

Firefox browser python 3.7

bokeh                     2.1.1                    py37_0
holoviews                 1.13.3                     py_0
ipykernel                 5.3.0            py37h5ca1d4c_0    conda-forge
ipython                   7.16.1           py37h43977f1_0    conda-forge
panel                     0.9.7                      py_0    pyviz
param                     1.9.3                      py_0    pyviz
pyviz_comms               0.7.5                      py_0    pyviz

Description of expected behavior and the observed behavior

When using the FileDownload widget, the specified callback should return a different payload depending on the value of the dependent parameters. This works when auto=True but not with auto=False

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn
import param
from io import StringIO

pn.extension()

class Download(param.Parameterized):
    content = param.Selector(default='foo', objects=['foo', 'bar'])

    def __init__(self, **params):
        super(Download, self).__init__(**params)
        self.download_widget = pn.widgets.FileDownload(callback=self.export_callback, filename='filename.txt', auto=False)

    @pn.depends('content')
    def export_callback(self):
        io = StringIO()

        io.write(self.content)
        io.seek(0)

        return io

    def panel(self):
        return pn.Row(self.param, self.download_widget)

d = Download()
d.panel()
maximlt commented 4 years ago

Thanks I could reproduce that!

With auto=False the widget acts first as a button (till it's clicked for the first time) and then always as a link (allowing right click to save as) that is indeed not being updated, which is why it always downloads the same data (even if the data contained by the widget on the python side is being updated).

I don't know how difficult it would be to fix that but for sure it's not that simple to support all the different cases well (embed, auto, callbacks, etc.). Would you like to support this case @philippjfr ?

philippjfr commented 4 years ago

I think we probably should yes or warn if you provide a callback with auto=False.

dbirman commented 2 months ago

Any chance this is going to get worked on? It would be really nice to have download buttons that you just "click" and they download an updated file based on the latest run of the callback, without transforming themselves into a clickable link. I poked around a bit in the file_download.ts file to see if this is an easy change, but it seems overly complex because the one download button needs to support a whole bunch of different behaviors?