Is there any way for calling databricks widget output from one notebook and use that as an input in another notebook?

Viewed 56

I have a use case where my first notebook is taking values from synapse pipeline as a widget.I want to pass the output of this widget as an input to the dataframe which is present in my second notebook.

FIRST NOTEBOOK

dbutils.widgets.text("input", "","")   //Input coming from synapse pipeline
"input": dbutils.widgets.get("input")
input = "/mnt/" + dbutils.widgets.get("input")
print(input)

SECOND NOTEBOOK

I want to use the input from first notebook to the second notebbok as show below.

% run FIRST NOTEBOOK
df = spark.read.csv(input)
1 Answers

it should be done differently - your first notebook need to run second notebook, not vice versa... Because the first notebook is the entry point when is called from the Synapse.

In your case, you can pass parameter to %run using the $variable syntax, and then pull that data using another widget (see docs).

So first notebook will look as following (in $input=$input, first $input is the name of variable, and second - refer to your input widget):

dbutils.widgets.text("input", "","")   //Input coming from synapse pipeline
"input": dbutils.widgets.get("input")
input = "/mnt/" + dbutils.widgets.get("input")
print(input)
%run ./FirstNotebook $input=$input

And the second notebook

input = "/mnt/" + dbutils.widgets.get("input")
df = spark.read.csv(input)
Related