cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass parameters to a notebook via URL?

Fisher73
New Contributor

I have a Notebook written in Python, and a Notebook's Dashboard that shows its result.

The Notebook has a parameters, processed with a text widget:

 

dbutils.widgets.text("p_test", "", "Enter Test Value")
p_test = dbutils.widgets.get("p_test")

 

When I enter a value in the widget's text box, it works ok.

The question. I want to call this notebook (more precisely speaking - its Dashboard) from another web page via a link, passing a value of the parameter in the URL.

The problem. If I copy the link to the dashboard and add a "...&p_test=my_value" at the end, the value is not passed to the widget and to the notebook.

I've found, in new-style AI/BI dashboards they pass parameters in the URL not by its names, but with its unique codes started from "f_nnnn..." so we can enter values to widgets, inspect these codes in the URL and use them to construct your own URL with your own values. But it looks like it does not work for dashboards linked to notebooks. I can't inspect any parameters in the URL while entering values to widgets and running the dashboard.

So, how can I call notebook's dashboard via link with parameters passed in the link?

1-Notebook.PNG2-AddToDashboard.PNG3-PassViaURL.PNG

2 REPLIES 2

NandiniN
Databricks Employee
Databricks Employee

To pass parameters to a notebook via URL in Databricks, you can use the %run magic command along with the parameters you want to pass.

When you run the notebook, you can pass the parameters using the %run command followed by the notebook path and the parameters.

%run /path/to/notebook $param1="value1" $param2="value2"

In this example, param1 and param2 are the names of the widgets in the target notebook, and "value1" and "value2" are the values you want to pass to these parameters

Refer https://docs.databricks.com/en/notebooks/widgets.html

NandiniN
Databricks Employee
Databricks Employee

Okay, I tried what you are doing,

When you create a dashboard from the notebook, Databricks generates a unique URL for the dashboard. This URL typically does not expose the widget parameters directly.

I will try to find if there is an alternate way. 

 

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group