The notebook toolbar includes menus and icons that you can use to manage and edit the notebook.
To view previous versions of the notebook, click the “Last edit…” message to the right of the menus.
An updated cell design is available. This design is in Public Preview. For an orientation to the new UI and answers to common questions, see Orientation to the new cell UI. This page includes information about how to use both versions of the cell design.
To enable or disable the new cell design, open the editor settings page in the workspace. In the sidebar, click Developer. Under Experimental features, toggle New cell UI.
Notebooks contain a collection of two types of cells: code cells and Markdown cells. Code cells contain runnable code. Markdown cells contain Markdown code that renders into text and graphics when the cell is executed and can be used to document or illustrate your code. You can add or remove cells to your notebook to structure your work.
You can run a single cell, a group of cells, or run the whole notebook at once. A notebook cell can contain at most 10MB. Notebook cell output is limited to 20MB.
This feature is in Public Preview.
To explore tables and volumes available to use in the notebook, click at the left side of the notebook to open the schema browser. See Browse data for more details.
Notebooks have two types of cells: code and Markdown. The contents of Markdown cells are rendered into HTML. For example, this snippet contains markup for a level-one heading:
%md ### Libraries
Import the necessary libraries.
renders as shown:
To create a new cell in the original UI, hover over a cell at the top or bottom and click the icon. You can also use the notebook cell menu: click and select Add Cell Above or Add Cell Below.
For a code cell, just type code into the cell. To create a Markdown cell, select Markdown from the cell’s language button or type
%md at the top of the cell.
There are several options to cut and copy cells. If you are using the Safari browser, only the keyboard shortcuts are available.
Use keyboard shortcuts:
Ctrl-Xto cut and
Use the Edit menu at the top of the notebook. Select Cut or Copy.
After you cut or copy cells, you can paste those cells elsewhere in the notebook, into a different notebook, or into a notebook in a different browser tab or window. To paste cells, use the keyboard shortcut
Ctrl-V. The cells are pasted below the current cell.
To undo cut or paste actions, you can use the keyboard shortcut
Ctrl-Z or the menu options Edit > Undo cut cells or Edit > Undo paste cells.
To select adjacent cells, click in a Markdown cell and then use Shift + Up or Down to select the cells above or below it. Use the edit menu to copy, cut, paste, or delete the selected cells as a group. To select all cells, select Edit > Select all cells or use the command mode shortcut Cmd+A.
To display an automatically generated table of contents, click the icon at the upper left of the notebook (between the left sidebar and the topmost cell). The table of contents is generated from the Markdown headings used in the notebook. If you are using the new UI, cells with titles also appear in the table of contents.
There are three display options for notebooks. Use the View menu to change the display option.
Standard view: results are displayed immediately after code cells.
Results only: only results are displayed.
Side-by-side: code and results cells are displayed side by side.
In the new UI, actions are available from icons in the cell gutter (the area to the right and left of the cell). For example, to move a cell up or down, use the grip dots in the left gutter. To delete a cell, use the trash can icon in the right gutter.
For easier editing, click the focus mode icon to display the cell at full width. To exit focus mode, click . You can also enlarge the displayed width of a cell by turning off View > Centered layout.
To automatically format all cells in the notebook to industry standard line lengths and spacing, select Edit > Format notebook.
To show or hide line numbers or command numbers, select Line numbers or Command numbers from the View menu. For line numbers, you can also use the keyboard shortcut Control+L.
If you enable line or command numbers, Databricks saves your preference and shows them in all of your other notebooks for that browser.
Command numbers above cells link to that specific command. If you click the command number for a cell, it updates your URL to be anchored to that command. To get a URL link to a specific command in your notebook, right-click the command number and choose Copy Link Address.
Line numbers are off by default in the new UI. To turn them on, select View > Line numbers. When a cell is in an error state, line numbers are displayed regardless of the selection.
The new UI does not include cell command number links. To get a URL link to a specific command in your notebook, click to open focus mode, and copy the URL from the browser address bar. To exit focus mode, click .
To add a title to a cell using the original UI, select Show Title from the cell actions menu.
To add a title to a cell using the new UI, do one of the following:
If command numbers are turned on (View > Command numbers), click the cell number shown at the center of the top of the cell and type the title.
If command numbers are turned off, select Add title from the cell actions menu.
With the new UI, cells that have titles appear in the notebook’s table of contents.
You can choose to display notebooks in dark mode. To turn dark mode on or off, select View > Theme and select Light theme or Dark theme.
Cell content consists of cell code and the results generated by running the cell. You can hide and show the cell code and result using the cell actions menu at the upper-right of the cell.
For related functionality, see Collapsible headings.
To hide cell code or results, click and select Hide Code or Hide Result. You can also select to display only the first line of a cell.
To show hidden cell code or results, click the Show links:
To hide cell code or results, click the kebab menu at the upper-right of the cell and select Hide code or Hide result. You can also select Collapse cell to display only the first line of a cell. To expand a collapsed cell, select Expand cell.
To show hidden cell code or results, click the show icon: .
Cells that appear after cells containing Markdown headings can be collapsed into the heading cell. To expand or collapse cells after cells containing Markdown headings throughout the notebook, select Collapse all headings from the View menu. The rest of this section describes how to expand or collapse a subset of cells.
For related functionality, see Hide and show cell content.
The image shows a level-two heading MLflow setup with the following two cells collapsed into it.
To expand and collapse headings, click the + and -.
You run notebooks on a Databricks cluster. This section describes how to attach to and detach from a cluster.
To attach a notebook to a cluster, you need the CAN ATTACH TO cluster-level permission.
As long as a notebook is attached to a cluster, any user with the CAN RUN permission on the notebook has implicit permission to access the cluster.
The menu shows a selection of clusters that you have used recently or that are currently running.
To select from all available clusters, click More…. Click on the cluster name to display a dropdown menu, and select an existing cluster.
You can also create a new cluster by selecting Create new resource… from the dropdown menu.
An attached notebook has the following Apache Spark variables defined.
Do not create a
SQLContext. Doing so will lead to inconsistent behavior.
To detach a notebook from a compute resource, click the compute selector in the notebook toolbar and hover over the attached cluster or SQL warehouse in the list to display a side menu. From the side menu, select Detach.
You can also detach notebooks from a cluster using the Notebooks tab on the cluster details page.
When you detach a notebook, the execution context is removed and all computed variable values are cleared from the notebook.
Databricks recommends that you detach unused notebooks from clusters. This frees up memory space on the driver.