Databricks widgets

Input widgets allow you to add parameters to your notebooks and dashboards. The widget API consists of calls to create various types of input widgets, remove them, and get bound values.

In Databricks Runtime 11.0 and above, you can also use ipywidgets in Databricks notebooks.

Databricks widgets are best for:

  • Building a notebook or dashboard that is re-executed with different parameters
  • Quickly exploring results of a single query with different parameters

View the documentation for the widget API in Scala, Python, and R with the following command:

dbutils.widgets.help()
dbutils.widgets.help("text")
dbutils.widgets.help("dropdown")

Databricks widget types

There are 4 types of widgets:

  • text: Input a value in a text box.
  • dropdown: Select a value from a list of provided values.
  • combobox: Combination of text and dropdown. Select a value from a provided list or input one in the text box.
  • multiselect: Select one or more values from a list of provided values.

Databricks widget example

Create a simple text widget.

dbutils.widgets.text("param1", "", "Input param")
param1 = dbutils.widgets.get("param1")
print(param1)

Create a simple dropdown widget.

dbutils.widgets.dropdown("X", "1", [str(x) for x in range(1, 10)])

You can access the current value of the widget with the call:

dbutils.widgets.get("X")

Finally, you can remove a widget or all widgets in a notebook:

dbutils.widgets.remove("X")

dbutils.widgets.removeAll()

Use Databricks widgets with %run

%run /path/to/notebook $X="10" $Y="1"
%run ./test_job $param1="bar"