directoryconfigurationdefaultjupyter-labfile-browser

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!


Solution

  • 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.