Not possible to access selected file name in Panel FileInput widget!

Hello,

I am using python Panel FileInput widget (panel==0.13.0) to upload a file. Upload works, but I can’n find a way to access uploaded file name. However, after selecting file the widget displays filename next to it, but filename is not included in objects, nor filename,…

Using file_input.get_param_values(), I will get filename=None…

> import panel as pn
> 
> class WidgetManager:
>     def __init__(self):
>         self.load_row = self.load_file_widget()
> 
>     def load_file_widget(self):
>         # Create a row of widgets for file load
>         self.file_input = pn.widgets.FileInput(accept='.csv')
>         load_row = pn.Row(self.file_input)
>         print(self.file_input.filename)
>         return load_row
> 
> # Create an instance of the WidgetManager class
> widget_manager = WidgetManager()
> 
> # Create a FastList dashboard and add the widgets to it
> dashboard = pn.Column(widget_manager.load_row)
> 
> # Show the dashboard
> dashboard.show()

Any idea how can I access to the uploaded filename?

1 Like

I would also be interested in having the answer to this.
It seems strange that all displayed filename are reset while only one variable is modified.

Is what you are looking for the the filename parameter?

import panel as pn

file_input = pn.widgets.FileInput(accept=".csv")


# Create a FastList dashboard and add the widgets to it
dashboard = pn.Column(file_input, file_input.param.filename)

pn.bind(print, file_input.param.filename, watch=True)

# Show the dashboard
dashboard.show()

Actually, I can not access to the filename value, since e.g. I want to change the filename. Using your code, the print(file_input.param.filename), returns <param.ClassSelector at 0x151da02c0>, while I want to have the name of the file as a variable.

1 Like

Hi @LeoSSK

file_input.param.filename is the parameter holding the value. If you want to access the value its at file_input.filename.

Please note initially file_input.filename is empty. But after you upload the file it has the file name.

1 Like

Dear Marc,

Thank you very much for your quick answer. However, the problem is that file_input.filename is always None, even after uploading a file.

Hi @LeoSSK

It works like illustrated below for me

1 Like

It is really strange. Now, I have the filename, where it was None till today morning… Could be because of param version or…?

I’ll deploy the code in our dashboards and will check if it is ok or not.
Thank you very much for your consideration @Marc

1 Like