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?
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.