urls.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. .. _urls:
  2. JupyterLab URLs
  3. ===============
  4. Like the classic notebook, JupyterLab provides a way for users to copy URLs that
  5. open a specific notebook or file. Additionally, JupyterLab URLs are an advanced
  6. part of the user interface that allows for managing workspaces. These two
  7. functions -- file paths and workspaces -- can be :ref:`combined in URLs that open a
  8. specific file in a specific workspace <url-combine>`.
  9. .. _url-tree:
  10. File Navigation with ``/tree``
  11. ------------------------------
  12. JupyterLab's file navigation URLs adopts
  13. the nomenclature of the classic notebook; these URLs are ``/tree`` URLs:
  14. .. code-block:: none
  15. http(s)://<server:port>/<lab-location>/lab/tree/path/to/notebook.ipynb
  16. Entering this URL will open the notebook in JupyterLab in
  17. :ref:`single-document mode <tabs>`.
  18. By default, the file browser will navigate to the directory containing the requested
  19. file. This behavior can be changed with the optional ``file-browser-path`` query parameter:
  20. .. code-block:: none
  21. http(s)://<server:port>/<lab-location>/lab/tree/path/to/notebook.ipynb?file-browser-path=/
  22. Entering the above URL will show the workspace root directory instead of the ``/path/to/``
  23. directory in the file browser.
  24. .. _url-workspaces-ui:
  25. Managing Workspaces (UI)
  26. ------------------------
  27. JupyterLab sessions always reside in a workspace. Workspaces contain the state
  28. of JupyterLab: the files that are currently open, the layout of the application
  29. areas and tabs, etc. When the page is refreshed, the workspace is restored.
  30. The default workspace does not have a name and resides at the primary ``/lab``
  31. URL:
  32. .. code-block:: none
  33. http(s)://<server:port>/<lab-location>/lab
  34. All other workspaces have a name that is part of the URL:
  35. .. code-block:: none
  36. http(s)://<server:port>/<lab-location>/lab/workspaces/foo
  37. Workspaces save their state on the server and can be shared between
  38. multiple users (or browsers) as long as they have access to the same server.
  39. A workspace should only be open in a single browser tab at a time. If JupyterLab
  40. detects that a workspace is being opened multiple times simultaneously, it will
  41. prompt for a new workspace name. Opening a document in two different browser
  42. tabs simultaneously is also not supported.
  43. .. _url-clone:
  44. Cloning Workspaces
  45. ------------------
  46. You can copy the contents of a workspace into another workspace with the ``clone`` url parameter.
  47. To copy the contents of the workspace ``foo`` into the workspace ``bar``:
  48. .. code-block:: none
  49. http(s)://<server:port>/<lab-location>/lab/workspaces/bar?clone=foo
  50. To copy the contents of the default workspace into the workspace ``foo``:
  51. .. code-block:: none
  52. http(s)://<server:port>/<lab-location>/lab/workspaces/foo?clone
  53. To copy the contents of the workspace ``foo`` into the default workspace:
  54. .. code-block:: none
  55. http(s)://<server:port>/<lab-location>/lab?clone=foo
  56. .. _url-reset:
  57. Resetting a Workspace
  58. ---------------------
  59. Use the ``reset`` url parameter to clear a workspace of its contents.
  60. To reset the contents of the workspace ``foo``:
  61. .. code-block:: none
  62. http(s)://<server:port>/<lab-location>/lab/workspaces/foo?reset
  63. To reset the contents of the default workspace:
  64. .. code-block:: none
  65. http(s)://<server:port>/<lab-location>/lab/workspaces/lab?reset
  66. .. _url-combine:
  67. Combining URL Functions
  68. -----------------------
  69. These URL functions can be used separately, as above, or in combination.
  70. To reset the workspace ``foo`` and load a specific notebook afterward:
  71. .. code-block:: none
  72. http(s)://<server:port>/<lab-location>/lab/workspaces/foo/tree/path/to/notebook.ipynb?reset
  73. To clone the contents of the workspace ``bar`` into the workspace ``foo`` and
  74. load a notebook afterward:
  75. .. code-block:: none
  76. http(s)://<server:port>/<lab-location>/lab/workspaces/foo/tree/path/to/notebook.ipynb?clone=bar
  77. To reset the contents of the default workspace and load a notebook:
  78. .. code-block:: none
  79. http(s)://<server:port>/<lab-location>/lab/tree/path/to/notebook.ipynb?reset
  80. .. _url-workspaces-cli:
  81. Managing Workspaces (CLI)
  82. -------------------------
  83. JupyterLab provides a command-line interface for workspace ``import`` and
  84. ``export``:
  85. .. code-block:: bash
  86. $ # Exports the default JupyterLab workspace
  87. $ jupyter lab workspaces export
  88. {"data": {}, "metadata": {"id": "/lab"}}
  89. $
  90. $ # Exports the workspaces named `foo`
  91. $ jupyter lab workspaces export foo
  92. {"data": {}, "metadata": {"id": "/lab/workspaces/foo"}}
  93. $
  94. $ # Exports the workspace named `foo` into a file called `file_name.json`
  95. $ jupyter lab workspaces export foo > file_name.json
  96. $
  97. $ # Imports the workspace file `file_name.json`.
  98. $ jupyter lab workspaces import file_name.json
  99. Saved workspace: <workspaces-directory>/labworkspacesfoo-54d5.jupyterlab-workspace
  100. The ``export`` functionality is as friendly as possible: if a workspace does not
  101. exist, it will still generate an empty workspace for export.
  102. The ``import`` functionality validates the structure of the workspace file and
  103. validates the ``id`` field in the workspace ``metadata`` to make sure its URL is
  104. compatible with either the ``workspaces_url`` configuration or the ``page_url``
  105. configuration to verify that it is a correctly named workspace or it is the
  106. default workspace.
  107. Workspace File Format
  108. ---------------------
  109. A workspace file in a JSON file with a specific spec.
  110. There are two top level keys requires, `data`, and `metadata`.
  111. The `metadata` must be a mapping with an `id`
  112. key that has the same value as the ID of the workspace. This should also be the relative URL path to access the workspace,
  113. like `/lab/workspaces/foo`.
  114. The `data` key maps to the initial state of the `IStateDB`. Many plugins look in the State DB for the configuration.
  115. Also any plugins that register with the `ILayoutRestorer` will look up all keys in the State DB
  116. that start with the `namespace` of their tracker before the first `:`. The values of these keys should have a `data`
  117. attribute that maps.
  118. For example, if your workspace looks like this:
  119. .. code-block:: bash
  120. {
  121. "data": {
  122. "application-mimedocuments:package.json:JSON": {
  123. "data": { "path": "package.json", "factory": "JSON" }
  124. }
  125. }
  126. }
  127. It will run the `docmanager:open` with the `{ "path": "package.json", "factory": "JSON" }` args, because the `application-mimedocuments` tracker is registerd with the `docmanager:open` command, like this:
  128. .. code-block:: typescript
  129. const namespace = 'application-mimedocuments';
  130. const tracker = new WidgetTracker<MimeDocument>({ namespace });
  131. void restorer.restore(tracker, {
  132. command: 'docmanager:open',
  133. args: widget => ({
  134. path: widget.context.path,
  135. factory: Private.factoryNameProperty.get(widget)
  136. }),
  137. name: widget =>
  138. `${widget.context.path}:${Private.factoryNameProperty.get(widget)}`
  139. });
  140. Not that the part of the data key after the first `:`, `package.json:JSON` is dropped and is irrelevent.