file_formats.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. [screenshot]
  16. To use these different data formats as output in a notebook or code
  17. console, you can use the relevant display API for the kernel you are
  18. using. For example, the IPython kernel provides a variety of convenience
  19. classes for displaying rich output:
  20. .. code:: python
  21. from IPython.display import display, HTML
  22. display(HTML('<h1>Hello World</h1>'))
  23. Running this code will display the HTML in the output of a notebook or
  24. code console cell:
  25. [screenshot]
  26. The IPython display function can also construct a raw rich output
  27. message from a dictionary of keys (MIME types) and values (MIME data):
  28. .. code:: python
  29. from IPython.display import display
  30. display({'text/html': '<h1>Hello World</h1>', 'text/plain': 'Hello World'}, raw=True)
  31. Other Jupyter kernels offer similar APIs.
  32. The rest of this section highlights some of the common data formats that
  33. JupyterLab supports.
  34. Markdown
  35. ~~~~~~~~
  36. - File extension: ``.md``
  37. - MIME type: ``text/markdown``
  38. Markdown is a simple and popular markup language used for text cells in
  39. the Jupyter Notebook.
  40. Markdown documents can be edited as text files or rendered inline:
  41. [animation showing opening a markdown document editor and renderer
  42. side-by-side, and changes in the editor being reflected in the renderer]
  43. The Markdown syntax supported in this mode is the same syntax used in
  44. the Jupyter Notebook (for example, LaTeX equations work). As seen in the
  45. animation, edits to the Markdown source are immediately reflected in the
  46. rendered version.
  47. Images
  48. ~~~~~~
  49. - File extensions: ``.bmp``, ``.gif``, ``.jpeg``, ``.jpg``, ``.png``,
  50. ``.svg``
  51. - MIME types: ``image/bmp``, ``image/gif``, ``image/jpeg``,
  52. ``image/png``, ``image/svg+xml``
  53. JupyterLab supports image data in cell output and as files in the above
  54. formats. In the image file viewer, you can use keyboard shortcuts such
  55. as ``+`` and ``-`` to zoom the image and ``0`` to reset the zoom level.
  56. To edit an SVG image as a text file, right-click on the SVG filename in
  57. the file browser and select the “Editor” item in the “Open With”
  58. submenu:
  59. [animation]
  60. CSV
  61. ~~~
  62. - File extension: ``.csv``
  63. - MIME type: None
  64. Files with rows of comma-separated values (CSV files) are a common
  65. format for tabular data. The default viewer for CSV files in JupyterLab
  66. is a high-performance data grid viewer (which can also handle tab- and
  67. semicolon-separated values):
  68. [animation]
  69. To edit a CSV file as a text file, right-click on the file in the file
  70. browser and select the “Editor” item in the “Open With” submenu:
  71. [animation]
  72. JSON
  73. ~~~~
  74. - File extension: ``.json``
  75. - MIME type: ``application/json``
  76. JavaScript Object Notation (JSON) files are common in data science.
  77. JupyterLab supports displaying JSON data in cell output or viewing a
  78. JSON file using a searchable tree view:
  79. [animation showing both rendering JSON as cell output and viewing a JSON
  80. file]
  81. To edit the JSON as a text file, right-click on the filename in the file
  82. browser and select the “Editor” item in the “Open With” submenu:
  83. [animation]
  84. HTML
  85. ~~~~
  86. - File extension: ``.html``
  87. - MIME type: ``text/html``
  88. JupyterLab supports rendering HTML in cell output and editing HTML files
  89. as text in the file editor.
  90. LaTeX
  91. ~~~~~
  92. - File extension: ``.tex``
  93. - MIME type: ``text/latex``
  94. JupyterLab supports rendering LaTeX equations in cell output and editing
  95. LaTeX files as text in the file editor.
  96. PDF
  97. ~~~
  98. - File extension: ``.pdf``
  99. - MIME type: ``application/pdf``
  100. PDF is a common standard file format for documents. To view a PDF file
  101. in JupyterLab, double-click on the file in the file browser:
  102. [animation]
  103. Vega/Vega-Lite
  104. ~~~~~~~~~~~~~~
  105. Vega:
  106. - File extensions: ``.vg``, ``.vg.json``
  107. - MIME type: ``application/vnd.vega.v2+json``
  108. Vega-Lite:
  109. - File extensions: ``.vl``, ``.vl.json``
  110. - MIME type: ``application/vnd.vegalite.v1+json``
  111. Vega and Vega-Lite are declarative visualization grammars that allow
  112. visualizations to be encoded as JSON data. For more information, see the
  113. documentation of Vega or Vega-Lite. JupyterLab supports rendering Vega
  114. 2.x and Vega-Lite 1.x data in files and cell output.
  115. Vega-Lite 1.x files, with a ``.vl`` or ``.vl.json`` file extension, can
  116. be opened by double-clicking the file in the File Browser:
  117. [animation]
  118. The files can also be opened in the JSON viewer or file editor through
  119. the “Open With…” submenu in the file browser content menu:
  120. [animation]
  121. As with other files in JupyterLab, multiple views of a single file
  122. remain synchronized, allowing you to interactively edit and render
  123. Vega-Lite/Vega visualizations:
  124. [animation]
  125. The same workflow also works for Vega 2.x files, with a ``.vg`` or
  126. ``.vg.json`` file extension.
  127. Output support for Vega/Vega-Lite in a notebook or code console is
  128. provided through third-party libraries such as Altair (Python), the
  129. vegalite R package, or Vegas (Scala/Spark).
  130. [screenshot]
  131. A JupyterLab extension that supports Vega 3.x and Vega-Lite 2.x can be
  132. found `here <https://github.com/jupyterlab/jupyter-renderers>`__.
  133. Virtual DOM
  134. ~~~~~~~~~~~
  135. - File extensions: ``.vdom``, ``.json``
  136. - MIME type: ``application/vdom.v1+json``
  137. Virtual DOM libraries such as `react.js <https://reactjs.org/>`__ have
  138. greatly improved the experience of rendering interactive content in
  139. HTML. The nteract project, which collaborates closely with Project
  140. Jupyter, has created a `declarative JSON
  141. format <https://github.com/nteract/vdom>`__ for virtual DOM data.
  142. JupyterLab can render this data using react.js. This works for both VDOM
  143. files with the ``.vdom`` extension, or within notebook output.
  144. Here is an example of a ``.vdom`` file being edited and rendered
  145. interactively:
  146. [animation]
  147. The `nteract/vdom <https://github.com/nteract/vdom>`__ library provides
  148. a Python API for creating VDOM output that is rendered in nteract and
  149. JupyterLab:
  150. [screenshot or animation]