FileSelector#

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).


import panel as pn
pn.extension()

The FileSelector widget allows browsing the filesystem on the server and selecting one or more files in a directory.

Discover more on using widgets to add interactivity to your applications in the how-to guides on interactivity. Alternatively, learn how to set up callbacks and (JS-)links between parameters or how to use them as part of declarative UIs with Param.

Parameters:#

For details on other options for customizing the component see the layout and styling how-to guides.

Core#

  • directory (str): The directory to browse (cannot access files above this directory).

  • file_pattern (str, default=’*’): A glob-like query expression to limit the displayed files.

  • only_files (bool, default=False): Whether to only allow selecting files.

  • refresh_period (int, default=None): If set to non-None value indicates how frequently to refresh the directory contents in milliseconds.

  • root_directory (str, default=None): If set to non-None value overrides directory parameter as the root directory beyond which users cannot navigate.

  • show_hidden (bool, default=False): Whether to show hidden files and directories (starting with a period).

  • value (list[str]): A list of file names.

Display#

  • name (str): The title of the widget


The FileSelector widget allows exploring the specified directory on the server’s filesystem and any directories contained within it. The widget consists of the navigation bar with a number of buttons and the address bar:

  • Back (): Goes to the previous directory

  • Forward (): Returns to the last directory after navigating back

  • Up (): Goes one directory up

  • Address bar: Display the directory to navigate to

  • Enter (): Navigates to the directory in the address bar

  • Reload (): Reloads the contents of the current directory

The actual file selector displays the contents of the current directory, to navigate to a subfolder click on a directory in the file selector and then hit the down arrow () in the navigation bar. Files and folders may be selected by selecting them in the browser on the left and moving them to the right with the arrow buttons:

files = pn.widgets.FileSelector('~')

files

To get the currently selected files simply access the value parameter:

files.value
[]

Open this notebook in Jupyterlite | Download this notebook from GitHub (right-click to download).