panel icon indicating copy to clipboard operation
panel copied to clipboard

Filedownload callback doesnt work with auto=False

Open Jhsmit opened this issue 5 years ago • 3 comments

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()

Jhsmit avatar Jul 08 '20 18:07 Jhsmit

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 ?

maximlt avatar Jul 09 '20 13:07 maximlt

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

philippjfr avatar Jul 26 '20 19:07 philippjfr

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?

dbirman avatar Aug 16 '24 05:08 dbirman