- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2021 10:31 PM
I have a scheduled a notebook. can I keep current date as default in widget whenever the notebook run and also i need the flexibility to change the widget value to any other date based on the ad hoc run that I do.
- Labels:
-
Current Date
-
Date
-
Widget
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2021 12:17 AM
second parameter is default value, here is example code:
data = [{"Category": 'Category A', "ID": 1, "Value": 12.40},
{"Category": 'Category B', "ID": 2, "Value": 30.10},
{"Category": 'Category C', "ID": 3, "Value": 100.01}
]
df = spark.createDataFrame(data)
values = [row.ID for row in df.select('ID').collect()]
default_value = str(max(values))
values_str = [str(value) for value in values]
dbutils.widgets.dropdown("ID", default_value, values_str)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2021 12:17 AM
second parameter is default value, here is example code:
data = [{"Category": 'Category A', "ID": 1, "Value": 12.40},
{"Category": 'Category B', "ID": 2, "Value": 30.10},
{"Category": 'Category C', "ID": 3, "Value": 100.01}
]
df = spark.createDataFrame(data)
values = [row.ID for row in df.select('ID').collect()]
default_value = str(max(values))
values_str = [str(value) for value in values]
dbutils.widgets.dropdown("ID", default_value, values_str)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2021 01:01 AM
So building on the answer of Hubert:
from datetime import date
date_for_widget = date.today()
So if you use date_for_widget as your default value, you are there.
And ofc you can fill this date_for_widget variable with anything you want.
You can even fetch a value from outside databricks, f.e. with Azure Data Factory.

