# Declarative class serving up FileDownload

**URL:** <https://discourse.holoviz.org/t/declarative-class-serving-up-filedownload/5385>\
**Category:** Panel\
**Tags:** param, filedownload\
**Created:** [May 23, 2023, 11:26am UTC](https://discourse.holoviz.org/t/declarative-class-serving-up-filedownload/5385 "2023-05-23T11:26:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidPMika](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/davidpmika/32/4927_2.png) [@DavidPMika](https://discourse.holoviz.org/u/DavidPMika)\
**Post date:** [May 23, 2023, 11:26am UTC](https://discourse.holoviz.org/t/declarative-class-serving-up-filedownload/5385/1 "2023-05-23T11:26:27Z")

</div>

I am trying to generate a FileDownload widget from a parameter in a declarative-style class, but am unable to get it to work.

Including the widgets dictionary that maps my parameter ‘select’ to widgets.FileDownload results in the error:

AttributeError: type object ‘FileDownload.param’ has no attribute ‘value’

What am I missing here?

```auto
import param
import panel as pn
import numpy as np
import pandas as pd

pn.extension()

class CustomExample(param.Parameterized):

    select = param.Action(lambda x: x._getData_requested(), label='Get Data')

    def __init__ (self, **params):
        super(). __init__ (**params)
        np.random.seed(5)
        self.df = pd.DataFrame(np.random.randint(100, size=(100, 6)),
                          columns=list('ABCDEF'),
                          index=['R{}'.format(i) for i in range(100)])
        
    def _getData_requested(self):
        print('data requested')
        from io import StringIO
        sio = StringIO()
        self.df.to_csv(sio)
        sio.seek(0)
        self.value = sio
        return sio
        
pn.Param(CustomExample.param, widgets={
    'select': pn.widgets.FileDownload}
    )
    
custom = CustomExample()
pn.panel(custom).servable()

```

---

<div class="post-metadata">

**Author:** ![DavidPMika](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/davidpmika/32/4927_2.png) [@DavidPMika](https://discourse.holoviz.org/u/DavidPMika)\
**Post date:** [June 1, 2023, 12:15am UTC](https://discourse.holoviz.org/t/declarative-class-serving-up-filedownload/5385/2 "2023-06-01T00:15:34Z")

</div>

As far as I can determine, there is no param that maps to FileDownload, so it must be explicitly instantiated in a declarative class. Here is a working example:

```auto
import param
import panel as pn
import numpy as np
import pandas as pd

pn.extension()

class CustomExample(param.Parameterized):

    select = param.Action(lambda x: x.do_cool_stuff(), label='Cool Stuff!')

    def __init__ (self, **params):
        super(). __init__ (**params)
        np.random.seed(5)
        self.df = pd.DataFrame(np.random.randint(100, size=(100, 6)),
                               columns=list('ABCDEF'),
                               index=['R{}'.format(i) for i in range(100)])

    def do_cool_stuff(self):
        print('doing something cool!')

    def _getData_requested(self):
        print('data requested!')
        from io import StringIO
        sio = StringIO()
        self.df.to_csv(sio)
        sio.seek(0)
        self.value = sio
        return sio

    def create_view(self):
        widgets = pn.Param(
            self,
            name='Data Viewer',
            parameters=['select']
        )
        # Must explicitly instantiate FileDownload widget as there
        # is no param that maps to it.
        widget = pn.widgets.FileDownload(
            callback=pn.bind(self._getData_requested), filename='file.csv',
            button_type='primary', label='Download')
        column = pn.Column(widgets, widget)
        return column

custom = CustomExample()
pn.panel(custom.create_view).servable()

```
