file_formats.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. .. _file-and-output-formats:
  2. File and Output Formats
  3. =======================
  4. JupyterLab provides a unified architecture for viewing and editing data
  5. in a wide variety of formats. This model applies whether the data is in
  6. a file or is provided by a kernel as rich cell output in a notebook or
  7. code console.
  8. For files, the data format is detected by the extension of the file (or
  9. the whole filename if there is no extension). A single file extension
  10. may have multiple editors or viewers registered. For example, a Markdown
  11. file (``.md``) can be edited in the file editor or rendered and
  12. displayed as HTML. You can open different editors and viewers for a file
  13. by right-clicking on the filename in the file browser and using the
  14. “Open With” submenu:
  15. .. image:: images/file_formats_open_with.png
  16. :align: center
  17. :class: jp-screenshot
  18. To use these different data formats as output in a notebook or code
  19. console, you can use the relevant display API for the kernel you are
  20. using. For example, the IPython kernel provides a variety of convenience
  21. classes for displaying rich output:
  22. .. code:: python
  23. from IPython.display import display, HTML
  24. display(HTML('<h1>Hello World</h1>'))
  25. Running this code will display the HTML in the output of a notebook or
  26. code console cell:
  27. .. image:: images/file_formats_html_display.png
  28. :align: center
  29. :class: jp-screenshot
  30. The IPython display function can also construct a raw rich output
  31. message from a dictionary of keys (MIME types) and values (MIME data):
  32. .. code:: python
  33. from IPython.display import display
  34. display({'text/html': '<h1>Hello World</h1>', 'text/plain': 'Hello World'}, raw=True)
  35. Other Jupyter kernels offer similar APIs.
  36. The rest of this section highlights some of the common data formats that
  37. JupyterLab supports by default. JupyterLab extensions can also add support for
  38. other file formats.
  39. .. _markdown:
  40. Markdown
  41. --------
  42. - File extension: ``.md``
  43. - MIME type: ``text/markdown``
  44. Markdown is a simple and popular markup language used for text cells in
  45. the Jupyter Notebook.
  46. .. _edit-markdown:
  47. Markdown documents can be edited as text files or rendered inline:
  48. .. raw:: html
  49. <div class="jp-youtube-video">
  50. <iframe src="https://www.youtube-nocookie.com/embed/eQsRlqK-z1c?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  51. </div>
  52. The Markdown syntax supported in this mode is the same syntax used in
  53. the Jupyter Notebook (for example, LaTeX equations work). As seen in the
  54. animation, edits to the Markdown source are immediately reflected in the
  55. rendered version.
  56. Images
  57. ------
  58. - File extensions: ``.bmp``, ``.gif``, ``.jpeg``, ``.jpg``, ``.png``,
  59. ``.svg``
  60. - MIME types: ``image/bmp``, ``image/gif``, ``image/jpeg``,
  61. ``image/png``, ``image/svg+xml``
  62. JupyterLab supports image data in cell output and as files in the above
  63. formats. In the image file viewer, you can use keyboard shortcuts such
  64. as ``+`` and ``-`` to zoom the image, ``[`` and ``]`` to rotate the image,
  65. and ``H`` and ``V`` to flip the image horizontally and vertically. Use
  66. ``I`` to invert the colors, and use ``0`` to reset the image.
  67. .. _edit-svg:
  68. To edit an SVG image as a text file, right-click on the SVG filename in
  69. the file browser and select the “Editor” item in the “Open With”
  70. submenu:
  71. .. raw:: html
  72. <div class="jp-youtube-video">
  73. <iframe src="https://www.youtube-nocookie.com/embed/y_ydmAmVdCA?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  74. </div>
  75. .. _csv:
  76. Delimiter-separated Values
  77. --------------------------
  78. - File extension: ``.csv``
  79. - MIME type: None
  80. .. _view-csv:
  81. Files with rows of delimiter-separated values, such as CSV files, are a common format for
  82. tabular data. The default viewer for these files in JupyterLab is a
  83. high-performance data grid viewer which can display comma-separated, tab-separated, and
  84. semicolon-separated values:
  85. .. raw:: html
  86. <div class="jp-youtube-video">
  87. <iframe src="https://www.youtube-nocookie.com/embed/z6xuZ9H3Imo?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  88. </div>
  89. While tab-separated value files can be read by the grid viewer, it currently does not automatically recognize ``.tsv`` files.
  90. To view, you must change the extension to ``.csv`` and set the delimiter to tabs.
  91. .. _edit-csv:
  92. To edit a CSV file as a text file, right-click on the file in the file
  93. browser and select the “Editor” item in the “Open With” submenu:
  94. .. raw:: html
  95. <div class="jp-youtube-video">
  96. <iframe src="https://www.youtube-nocookie.com/embed/b5oAoVB3Wd4?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  97. </div>
  98. JupyterLab's grid viewer can open large files, up to the maximum string size of the particular browser.
  99. Below is a table that shows the sizes of the largest test files we successfully opened in each browser we support:
  100. +---------+----------+
  101. | Browser | Max Size |
  102. +=========+==========+
  103. | Firefox | 1.04GB |
  104. +---------+----------+
  105. | Chrome | 730MB |
  106. +---------+----------+
  107. | Safari | 1.8GB |
  108. +---------+----------+
  109. The actual maximum size of files that can be successfully loaded will vary depending on the browser version and file content.
  110. JSON
  111. ----
  112. - File extension: ``.json``
  113. - MIME type: ``application/json``
  114. .. _view-json:
  115. JavaScript Object Notation (JSON) files are common in data science.
  116. JupyterLab supports displaying JSON data in cell output or viewing a
  117. JSON file using a searchable tree view:
  118. .. raw:: html
  119. <div class="jp-youtube-video">
  120. <iframe src="https://www.youtube-nocookie.com/embed/FRj1r7-7kiQ?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  121. </div>
  122. .. _edit-json:
  123. To edit the JSON as a text file, right-click on the filename in the file
  124. browser and select the “Editor” item in the “Open With” submenu:
  125. .. raw:: html
  126. <div class="jp-youtube-video">
  127. <iframe src="https://www.youtube-nocookie.com/embed/HKcJAGZngzw?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  128. </div>
  129. HTML
  130. ----
  131. - File extension: ``.html``
  132. - MIME type: ``text/html``
  133. JupyterLab supports rendering HTML in cell output and editing HTML files
  134. as text in the file editor.
  135. LaTeX
  136. -----
  137. - File extension: ``.tex``
  138. - MIME type: ``text/latex``
  139. JupyterLab supports rendering LaTeX equations in cell output and editing
  140. LaTeX files as text in the file editor.
  141. PDF
  142. ---
  143. - File extension: ``.pdf``
  144. - MIME type: ``application/pdf``
  145. .. _view-pdf:
  146. PDF is a common standard file format for documents. To view a PDF file
  147. in JupyterLab, double-click on the file in the file browser:
  148. .. raw:: html
  149. <div class="jp-youtube-video">
  150. <iframe src="https://www.youtube-nocookie.com/embed/vLAEzD5dxQw?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  151. </div>
  152. .. _vega-lite:
  153. Vega/Vega-Lite
  154. --------------
  155. Vega:
  156. - File extensions: ``.vg``, ``.vg.json``
  157. - MIME type: ``application/vnd.vega.v5+json``
  158. Vega-Lite:
  159. - File extensions: ``.vl``, ``.vl.json``
  160. - MIME type: ``application/vnd.vegalite.v3+json``
  161. Vega and Vega-Lite are declarative visualization grammars that enable
  162. visualizations to be encoded as JSON data. For more information, see the
  163. documentation of Vega or Vega-Lite. JupyterLab supports rendering Vega
  164. 5.x and Vega-Lite 3.x data in files and cell output.
  165. .. _open-vega:
  166. Vega-Lite 1.x files, with a ``.vl`` or ``.vl.json`` file extension, can
  167. be opened by double-clicking the file in the file browser:
  168. .. raw:: html
  169. <div class="jp-youtube-video">
  170. <iframe src="https://www.youtube-nocookie.com/embed/Dddtyz5fWkU?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  171. </div>
  172. .. _open-vega-with:
  173. The files can also be opened in the JSON viewer or file editor through
  174. the “Open With…” submenu in the file browser content menu:
  175. .. raw:: html
  176. <div class="jp-youtube-video">
  177. <iframe src="https://www.youtube-nocookie.com/embed/qaiGRXh4jxc?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  178. </div>
  179. .. _vega-multiple-views:
  180. As with other files in JupyterLab, multiple views of a single file
  181. remain synchronized, enabling you to interactively edit and render
  182. Vega/Vega-Lite visualizations:
  183. .. raw:: html
  184. <div class="jp-youtube-video">
  185. <iframe src="https://www.youtube-nocookie.com/embed/4Me4rCeS8To?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  186. </div>
  187. The same workflow also works for Vega 2.x files, with a ``.vg`` or
  188. ``.vg.json`` file extension.
  189. Output support for Vega/Vega-Lite in a notebook or code console is
  190. provided through third-party libraries such as Altair (Python), the
  191. vegalite R package, or Vegas (Scala/Spark).
  192. .. image:: images/file_formats_altair.png
  193. :align: center
  194. :class: jp-screenshot
  195. A JupyterLab extension that supports Vega 3.x and Vega-Lite 2.x can be
  196. found `here <https://github.com/jupyterlab/jupyter-renderers>`__.
  197. Virtual DOM
  198. -----------
  199. - File extensions: ``.vdom``, ``.json``
  200. - MIME type: ``application/vdom.v1+json``
  201. Virtual DOM libraries such as `react.js <https://reactjs.org/>`__ have
  202. greatly improved the experience of rendering interactive content in
  203. HTML. The nteract project, which collaborates closely with Project
  204. Jupyter, has created a `declarative JSON
  205. format <https://github.com/nteract/vdom>`__ for virtual DOM data.
  206. JupyterLab can render this data using react.js. This works for both VDOM
  207. files with the ``.vdom`` extension, or within notebook output.
  208. .. _edit-vdom:
  209. Here is an example of a ``.vdom`` file being edited and rendered
  210. interactively:
  211. .. raw:: html
  212. <div class="jp-youtube-video">
  213. <iframe src="https://www.youtube-nocookie.com/embed/fObR8xeKCJU?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
  214. </div>
  215. The `nteract/vdom <https://github.com/nteract/vdom>`__ library provides
  216. a Python API for creating VDOM output that is rendered in nteract and
  217. JupyterLab:
  218. .. image:: images/file_formats_nteract_vdom.png
  219. :align: center
  220. :class: jp-screenshot