dbutils.widgets.removeAll()

A Databricks notebook is an interactive, multi-language document that combines executable code, visualisations, and documentation in a single shareable artifact. Creating one takes seconds — attach it to compute, write your first cell, and press Shift+Enter to see results immediately.

    Who this is for:

    Part of the Getting Started with Databricks section of the Databricks tutorial series.

    Architecture / Concept Overview: dbutils.widgets.removeAll()

    Notebooks in Databricks execute code against a Spark cluster or SQL warehouse. Each notebook has a default language but can mix languages using magic commands. The notebook runtime maintains state between cells, so variables persist across executions within a session.

    %%{init: {"theme":"base","themeVariables":{"background":"#0B0E14","primaryTextColor":"#E0E6ED","lineColor":"#5D6470","darkMode":true,"primaryColor":"#2E4A4A","secondaryColor":"#374151","secondaryTextColor":"#E0E6ED","tertiaryColor":"#111827","tertiaryTextColor":"#E0E6ED","edgeLabelBackground":"#1f2937"}}}%% flowchart LR classDef source fill:#3F4B59,stroke:#9CA3AF,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef ingestion fill:#5A4B36,stroke:#C9A86B,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef processing fill:#535072,stroke:#8E82B4,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef storage fill:#2E4A4A,stroke:#5FAFA8,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef serving fill:#3D5550,stroke:#6BB7AA,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef governance fill:#5A3F52,stroke:#C28BB0,stroke-width:2px,rx:8,ry:8,color:#E0E6ED User[You] --> Notebook[Notebook] Notebook --> Cluster[Attached Cluster] Cluster --> Spark[Spark Engine] Spark --> Data[(Delta Tables)] Spark --> Results[Cell Results] Results --> Viz[Visualisation] class User source class Notebook ingestion class Cluster processing class Spark processing class Data storage class Results serving class Viz serving

    *Figure 1 — Notebook execution flow: your code runs on an attached cluster and returns results inline.*

    %%{init: {"theme":"base","themeVariables":{"background":"#0B0E14","primaryTextColor":"#E0E6ED","lineColor":"#5D6470","darkMode":true,"primaryColor":"#2E4A4A","secondaryColor":"#374151","secondaryTextColor":"#E0E6ED","tertiaryColor":"#111827","tertiaryTextColor":"#E0E6ED","edgeLabelBackground":"#1f2937"}}}%% graph TD classDef source fill:#3F4B59,stroke:#9CA3AF,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef ingestion fill:#5A4B36,stroke:#C9A86B,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef processing fill:#535072,stroke:#8E82B4,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef storage fill:#2E4A4A,stroke:#5FAFA8,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef serving fill:#3D5550,stroke:#6BB7AA,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef governance fill:#5A3F52,stroke:#C28BB0,stroke-width:2px,rx:8,ry:8,color:#E0E6ED NB[Notebook] NB --> Cell1[Python Cell] NB --> Cell2[SQL Cell] NB --> Cell3[Markdown Cell] NB --> Cell4[Python Cell] Cell1 --> State[Shared Session State] Cell2 --> State Cell4 --> State class NB processing class Cell1 serving class Cell2 storage class Cell3 source class Cell4 serving class State governance

    *Figure 2 — Notebook cells share session state; variables from one cell are available in subsequent cells.*

    %%{init: {"theme":"base","themeVariables":{"background":"#0B0E14","primaryTextColor":"#E0E6ED","lineColor":"#5D6470","darkMode":true,"primaryColor":"#2E4A4A","secondaryColor":"#374151","secondaryTextColor":"#E0E6ED","tertiaryColor":"#111827","tertiaryTextColor":"#E0E6ED","edgeLabelBackground":"#1f2937"}}}%% flowchart LR classDef source fill:#3F4B59,stroke:#9CA3AF,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef ingestion fill:#5A4B36,stroke:#C9A86B,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef processing fill:#535072,stroke:#8E82B4,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef storage fill:#2E4A4A,stroke:#5FAFA8,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef serving fill:#3D5550,stroke:#6BB7AA,stroke-width:2px,rx:8,ry:8,color:#E0E6ED classDef governance fill:#5A3F52,stroke:#C28BB0,stroke-width:2px,rx:8,ry:8,color:#E0E6ED Dev[Development] --> Share[Share Notebook] Share --> Collab[Collaborate] Collab --> Schedule[Schedule as Job] Schedule --> Prod[Production Pipeline] class Dev source class Share ingestion class Collab processing class Schedule governance class Prod serving

    *Figure 3 — Notebook lifecycle: develop interactively, share with colleagues, then schedule for production.*

    Key Terms

    Prerequisites and Setup

    • An active Databricks workspace with login access
    • A running cluster or permission to create one (or a SQL warehouse for SQL-only notebooks)
    • Basic familiarity with Python or SQL syntax
    • Understanding of what you want to explore (a dataset, a sample, or an experiment)

    Step-by-Step Implementation

      Configuration Reference

      dbutils.widgets.removeAll() configuration options
      FeatureShortcut / MethodDescription
      Run cellShift + EnterExecute current cell and advance
      Run cell in placeCtrl + EnterExecute without advancing
      Add cell aboveA (in command mode)Insert new cell above current
      Add cell belowB (in command mode)Insert new cell below current
      Delete cellD, D (in command mode)Delete current cell
      Toggle commentCtrl + /Comment/uncomment selected lines
      Auto-completeTabTrigger code completion
      Format codeCtrl + Shift + FAuto-format cell contents

      Monitoring, Cost, and Security Considerations

      Monitoring

      Monitor cluster utilisation while running notebooks via the Spark UI (accessible from the cluster page). Check cell execution times to identify slow operations. Use the notebook revision history to track changes over time.

      Cost Optimisation

      Detach from the cluster when not actively working (or rely on auto-termination). Avoid running display() on very large DataFrames — add a .limit() first. Use %sql cells with SQL warehouses instead of spinning up full clusters for simple queries.

      Security and Governance

      Do not hardcode credentials in notebook cells — use Databricks secrets (dbutils.secrets.get()). Be mindful of notebook sharing permissions — shared notebooks expose all cell content. Clear cell outputs containing sensitive data before sharing.

      Common Pitfalls and Recommended Patterns

      • Running cells out of order and encountering undefined variables — use "Run All" to verify sequential execution
      • Forgetting to attach a cluster before running — the notebook will prompt you, but it causes a delay
      • Using print() for DataFrames instead of display() — display provides richer formatting and visualisation options
      • Not using magic commands — writing SQL in a Python cell causes syntax errors; prefix with %sql
      • Creating huge DataFrames with toPandas() — this collects all data to the driver; add .limit() for exploration
      • Not documenting with markdown cells — notebooks become unreadable without context

      Frequently Asked Questions

      Can multiple people edit the same notebook?

      Yes. Databricks supports real-time co-authoring. You'll see other users' cursors and edits live, similar to Google Docs.

      Are notebook changes saved automatically?

      Yes. Databricks auto-saves notebook changes. You can also view and restore any previous version through revision history.

      Can I run a notebook as a scheduled job?

      Yes. Any notebook can be scheduled as a Databricks job. Navigate to Workflows, create a job, and select the notebook as the task source.

      How do I install additional Python packages?

      Use %pip install package_name in a cell. The package installs on the cluster for the current session. For persistent packages, use the cluster's Libraries configuration.

      Can I export notebooks to other formats?

      Yes. Export as .py (Python script), .ipynb (Jupyter), .dbc (Databricks archive), or HTML. Use File > Export from the notebook menu.