FileBrowser components
FileBrowser components browse files and directories on the server side.
FileBrowseropens files and can optionally select one path.FileBrowserMultipleselects multiple paths.
Both components use pathlib.Path values for selection callbacks. FileBrowser keeps string directory support for backwards compatibility. FileBrowserMultiple only accepts Path directory and selection values.
File/directory browser at the server side.
@solara.component
def FileBrowser(
directory: Union[None, str, Path, solara.Reactive[Path]] = None,
selected: Union[None, Path, solara.Reactive[Optional[Path]]] = None,
on_directory_change: Optional[Callable[[Path], None]] = None,
on_path_select: Optional[Callable[[Optional[Path]], None]] = None,
on_file_open: Optional[Callable[[Path], None]] = None,
filter: Callable[[Path], bool] = lambda x: True,
directory_first: bool = False,
on_file_name: Optional[Callable[[str], None]] = None,
start_directory=None,
can_select=False,
watch: bool = False,
):
...
There are two modes possible
can_select=Falseon_file_open: Triggered when single clicking a file or directory.on_path_select: Never triggeredon_directory_change: Triggered when clicking a directorycan_select=Trueon_file_open: Triggered when double clicking a file or directory.on_path_select: Triggered when clicking a file or directoryon_directory_change: Triggered when double clicking a directory
Arguments
directory: The directory to start in. IfNone, the current working directory is used.selected: The selected file or directory. IfNone, no file or directory is selected (requirescan_select=True).on_directory_change: Depends on mode, see above.on_path_select: Depends on mode, see above.on_file_open: Depends on mode, see above.filter: A function that takes aPathand returnsTrueif the file/directory should be shown.directory_first: IfTruedirectories are shown before files. Default:False.on_file_name: (deprecated) Use on_file_open instead.start_directory: (deprecated) Use directory instead.watch: IfTrue, watch the current directory for file changes and automatically refresh the file list. Requires thewatchfilespackage to be installed.
FileBrowserMultiple
File/directory browser that supports selecting multiple local paths.
@solara.component
def FileBrowserMultiple(
directory: Union[None, Path, solara.Reactive[Path]] = None,
selected: Union[None, List[Path], solara.Reactive[List[Path]]] = None,
on_paths_select: Optional[Callable[[List[Path]], None]] = None,
on_directory_change: Optional[Callable[[Path], None]] = None,
on_file_open: Optional[Callable[[Path], None]] = None,
filter: Callable[[Path], bool] = lambda x: True,
directory_first: bool = False,
watch: bool = False,
):
...
Selection values are always pathlib.Path instances. Unlike FileBrowser, this component does not accept string directories.
Single-clicking a file or directory toggles it in the selected path list. Double-clicking a file opens it, and double-clicking a directory navigates into it. Opening or navigating clears the current selection.
Arguments
directory: The directory to start in. IfNone, the current working directory is used.selected: The selected files or directories. IfNone, no path is selected.on_paths_select: Callback called with the selected path list.on_directory_change: Called when double-clicking a directory.on_file_open: Called when double-clicking a file.filter: A function that takes aPathand returnsTrueif the file/directory should be shown.directory_first: IfTruedirectories are shown before files. Default:False.watch: IfTrue, watch the current directory for file changes and automatically refresh the file list. Requires thewatchfilespackage to be installed.
FileBrowserMultiple selects multiple paths. The selected values are pathlib.Path objects.
FileBrowserMultiple
Selected paths:
- none