Hello,
I noticed that there is something that looks like a bug to me and causes some undesired behavior (adding folder icons to file names on the RHS of the widget as if those files were directories)
edit: versions: panel==0.10.3, bokeh==2.2.3
# panel/widgets/file_selector.py
...
class FileSelector(CompositeWidget):
...
def _update_files(self, event=None):
...
dirs, files = scan_path(path, self.file_pattern)
for s in selected:
check = os.path.realpath(s) if os.path.islink(s) else s
if os.path.isdir(check):
dirs.append(s)
elif os.path.isfile(check):
dirs.append(s)
...
I suspect that there should be files
instead of dirs
in the last line of this code. Am I correct?
About my issue:
I’m trying to force file selector to accept only a single file on the RHS. I solved it in a little hacky way:
import panel as pn
pn.extension()
files = pn.widgets.FileSelector('/files')
def callback(target, event):
if len(target.value) > 1:
target.value = [target.value[-1]]
target._update_files(target)
files.link(
files,
callbacks={'value': callback}
)
files
Which works as in gif below:
When I change dirs
to files
as mentioned in the beginning of this post, it works as expected - no folder icon is added.