FileDownload widget does not disable/enable correctly


I would like to enable and disable FileDownload button, however it seems not to refresh. See example below.


import panel as pn

b = pn.widgets.Button(name='Button', disabled=True)
db = pn.widgets.FileDownload(label='File download', disabled=True)
pn.Row(b, db)

b.disabled = False
db.disabled = False

pn.Row(b, db)

Sure looks like a bug! Depending on your requirements, the following may be a suitable workaround for the time being:

import panel as pn
from io import StringIO
from bokeh.sampledata.autompg import autompg

async_event = pn.widgets.Button(name='<some async event>', button_type='primary')
layout = None

def filtered_file():
    sio = StringIO()
    return sio

def db_cb(event=None):
    disabled = async_event.clicks % 2 == 0
    b.disabled = disabled
    db.disabled = disabled
    if isinstance(layout, pn.Row):
        layout[2] = db.clone()
    return db

b = pn.widgets.Button(name='Button')
db = pn.widgets.FileDownload(callback=filtered_file, label='File download', filename='filtered_autompg.csv')
layout = pn.Row(async_event, b, db_cb)

Thank you! This did the job for me.

I noticed a related issue was reported on github so I added a comment and a reference to this thread there.

thanks for the post. I was already convinced that my issue would be forever forgotten…