How to use FileUpload widget in jupyter lab?
For me it worked after
pip install jupyterlab-widgets jupyter labextension install @jupyter-widgets/jupyterlab-manager
from ipywidgets import FileUpload from IPython.display import display upload = FileUpload(accept='.txt', multiple=True) display(upload)
with open('z_merged_output.txt', 'wb') as output_file: for uploaded_filename in upload.value: content = upload.value[uploaded_filename]['content'] output_file.write(content)
If you're using jupyterlab out the box, it doesn't have ipywidgets enabled by default, you need to rebuild it after enabling the extension. Follow the steps from here:
- Install nodeJS
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager
- (may need to restart your lab)
It says that newer Jupyterlab has it enabled, but I still had troubles with it, depending on the platform. Manual install is usually the way to go.