Databricks Widgets
Databricks Widgets
🚀 Mastering PySpark
and Databricks 🚀
Part-21
Databricks Widgets
C .R. Anil Kumar Reddy
Associate Developer for Apache Spark 3.0
Databricks widgets
Input widgets allow you to add parameters to your notebooks and dashboards. You
can add a widget from the Databricks UI or using API.
The following table lists the available commands for this utility, which you
can retrieve using dbutils.widgets.help().
Let us discuss all the above widgets and commands one by one
The first argument for all widget types is name. This is the name you use
to access the widget.
The third argument for all widget types (except text) is choices, a list of
values the widget can take on. This argument is not used for text type
widgets.
The last argument is label, an optional value for the label shown over
the widget text box or dropdown.
Combobox
Combobox command (dbutils.widgets.combobox)
Example
Dropdown
dropdown command (dbutils.widgets.dropdown)
Example
Multiselect
Example
Text
Example
This example creates and displays a text widget with the programmatic
name env2. It offers the choices dev, test, prod, and is set to the initial
value of dev. This text widget has an accompanying label Environment Text.
This example ends by printing the initial value of the text widget, dev.
get command
get command (dbutils.widgets.get)
Gets the current value of the widget with the specified programmatic name.
Example
This example gets the value of the widget that has the programmatic name text .
getAll command
getAll command (dbutils.widgets.getAll)
getAll: map
Gets a mapping of all current widget names and values. This can be
especially useful to quickly pass widget values to a spark.sql() query.
DATA ANALYTICS
Happy Learning
www.linkedin.com/in/chenchuanil