Hi all,
TheOC here with my first of (hopefully!) many blogs on the Databricks Community. I'm hoping in this series to share quick, practical tips to help you get the most out of Databricks. Today's topic is: Widgets.
If you're anything like me, you've also fallen into the trap of building notebooks with hard-coded values (dates, environments, column names?). This works fine at first, but as soon as something changes, or we want to share our notebooks, it can become a pain. This is where we should look to use widgets!

Widgets are interactive inputs that can be added to your notebook. This completely negates the need to dig through your code to look for the particular hard-coded value, as now you can simply use the interface you have made to change this. It may feel a small thing, but it can easily make your life so much easier when looking to productionise notebooks.
Here are our options:
- Text Box (Free-text input, useful for things like dates or titles)
> dbutils.widgets.text() - Dropdown (Single-selection list input, useful for environments)
> dbutils.widgets.dropdown() - Combobox (Dropdown, plus the option to type in your own value)
> dbutils.widgets.combobox() - Multiselect (Dropdown, but allows for multiple options to be selected)
> dbutils.widgets.multiselect()

Let's look at creating some Widgets, to show you what that looks like!
I'm going to create 4 widgets with the following code:
# 1. Text box
dbutils.widgets.text("date", "2025-01-01", "Select Date")
# 2. Dropdown
dbutils.widgets.dropdown("environment", "dev", ["dev", "test", "prod"], "Environment")
# 3. Combobox
dbutils.widgets.combobox("region", "NA", ["NA", "EMEA", "APAC", "LATAM"], "Region")
# 4. Multiselect
dbutils.widgets.multiselect("columns", "sales", ["sales", "profit", "cost"], "Columns")
Let's see what that does:

As you can see, inserting this code and hitting run presents the user with 4 inputs: 'Select Date', 'Environment', 'Region', and 'Columns'.
Getting these into the notebook is great, but now we need to actually use these values entered. This can be done through:
> dbutils.widgets.get
(It's worth knowing that for multiselects, the value is returned as a comma separated list.)
Let's have a look at an example:

How cool is that? In just a few lines we've been able to create a user interface for our notebook, and utilise the values entered. I can't wait to use these on my production workflows to make them easier to reuse and share, and much more future-proofed.
These can easily be used to:
- Switch between Dev, Test, and Prod data sources
- Select Reporting Periods (P01, P02)
- Adjust SQL query filters or limits easily

That's it for the first instalment of Level Up Your Databricks Game. Widgets may seem a simple feature, but once you start using them you'll really unlock value in your projects.
I'd love to hear how you're already using widgets - or where you think you could use them.
Also, do let me know if there's anything specific you'd like me to cover in this series! I have my own ideas but I'd love to hear yours 😀
Cheers,
TheOC