I would like to show a file selection dialog, where users of my JupyterLab notebook can select a file from their workspace (= files on server, not from their local computer).
If I would try to use some python library (tkinter, qt), that would try to open a GUI on the server. However, I want to have a GUI on the client. Since the client runs in the browser, that GUI needs to be based on html/javascript.
Furthermore, the files to be selected are located on the server. A list of existing files can be shown with a system command (e.g. "!dir").
There seem to be widgets for file selection in JupyterLab:
https://jupyterlab.readthedocs.io/en/stable/developer/ui_helpers.html#file-dialogs
JavaScript code (requires a build step of Jupyterlab extension; FileDialog
needs to be imported from @jupyterlab/filebrowser; DocumentManager needs to be injected as plugin dependency from @jupyterlab/docmanager; ):
var { FileDialog } = require('@jupyterlab/filebrowser');
const dialog = FileDialog.getOpenFiles({
manager, // IDocumentManager
filter: model => model.type == 'notebook' // optional (model: Contents.IModel) => boolean
});
const result = await dialog;
if(result.button.accept){
let files = result.value;
}
=>How can I use those widgets in my python code? Is there some extra python library for doing so?
Unfortunately FileDialog
does not seem to be inlcuded in ipywidgets
:
import ipywidgets as widgets
print(dir(widgets))
Related:
https://discourse.jupyter.org/t/jupyterlab-file-chooser-widget-server-side/4934/3
ipywidgets
https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html
https://www.blog.pythonlibrary.org/2018/10/24/working-with-jupyter-notebook-widgets/
qt and tkinter