Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default folder in JupyterLab file browser?

I was wondering if there is a way to set a default folder every time I open JupyterLab. Is there any command I can run through Anaconda PowerShell Prompt? Or a JSON property I can modify in settings tab? Thanks in advance!

like image 728
NickS1 Avatar asked Oct 27 '25 10:10

NickS1


2 Answers

If you want to open specific file in directory a, say a/notebook.ipynb but then navigate the file browser to directory b, relative to the root directory, you can use file-browser-path query in the navigation URL (documented here):

http(s)://<server:port>/<lab-location>/lab/tree/a/notebook.ipynb?file-browser-path=/b

You can use this method from command line thanks to LabApp.default_url traitlet:

jupyter-lab --LabApp.default_url='/lab/tree/a/notebook.ipynb?file-browser-path=/b' 

You can skip the opening specific file part:

jupyter-lab --LabApp.default_url='/lab?file-browser-path=/b'

If you want to change the root directory, please see this answer which explains how to do so with ServerApp.root_dir traitlet (in older versions of Notebook<7.0 and JupyterLab<3.0 used to be named NotebookApp.notebook_dir). Again, you can use it from command line, and even specify an absolute path:

jupyter-lab --ServerApp.root_dir='/home/user/project/'
# or on Windows say:
# jupyter-lab --ServerApp.root_dir='C/users/user/project/'

You can combine the two approaches, e.g.:

jupyter-lab --ServerApp.root_dir='/home/user/project/' --LabApp.default_url='/lab?file-browser-path=/project_subdirectory'

If you want to persist the changes (for either default URL or root dir), see the previously linked answer which details how to persist configuration.

like image 124
krassowski Avatar answered Oct 30 '25 10:10

krassowski


According to the jupyter.org: I configured like this.

Terminal command active your envirnment by conda activate Your_env_name and then jupyter lab --generate-config. jupyter_lab_config.py should be created in dir /home/$USER/.jupyter directory.

Find # c.LabApp.app_settings_dir = '' and uncomment.

Then give your directory like this. c.LabApp.app_settings_dir = '/home/$USER/Documents/Jupyter_Notebook'

Similar for jupyter notebook. jupyter notebook --generate-config and then nu-comment and edit like c.NotebookApp.notebook_dir = '/home/UserName/Documents/Jupyter_Notebook'

**NB: /home/$USER/Documents/Jupyter_Notebook is my changed default dir. Change it according to your need. **

like image 30
BKumarAtanu Avatar answered Oct 30 '25 11:10

BKumarAtanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!