urls.rst 6.6 KB

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