cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically create a widget?

mehdi1
New Contributor III

I know the dbutils.widget.text to create a widget in a notebook. So for me the workflow

1. Having a notebook

2. Use dbutils.widget.text (or other type of widgets) once in a notebook cell to create a widget

3. Remove the cell containing dbutils.widget.text (because it's not usefull anymore)

4. Use dbutils.widget.get permanently in the notebook

Now I want to automate the following. I deploy a Jupyter notebook from a repo to a databricks workspace programmatically (using Azure devops). The deployment works fine using Databricks APIs, but only one thing is missing for me, the widget creation. Because manually creating the widget requires executing the cells with the widget.text call, how can I do that without having to run the cell manually, then remove it then come back to continue the deployment process.

1 ACCEPTED SOLUTION
9 REPLIES 9

Hubert-Dudek
Esteemed Contributor III

@Mehdi BEN ABDESSELEM​ , Did you try to run the job with that notebook with API?

https://docs.databricks.com/dev-tools/api/latest/jobs.html#operation/JobsRunsSubmit -

Create and trigger a one-time run POST to https://<databricks-instance>/api/2.1/jobs/runs/submit

mehdi1
New Contributor III

Good to know, thanks

mehdi1
New Contributor III

Good to know, thanks. I wonder if updating a notebook (overwriting the notebook with the API), will also remove the widget or not

ypm
New Contributor III

Hi @Mehdi BEN ABDESSELEM​ 

What is the reason for removing the creation of the widget (e.g. dbutils.widget.text) in the notebook? You could leave it there with a proper default value and run the notebook if you need to. Also, if you do not want to see the code of the creation script, you could simply hide it.

Hope this helps, @Yves Mauron​ ​ 

mehdi1
New Contributor III

The reason is I was concerned with the widget.text creation method would override the parameter sent through. But it seems it's not the case (even if I've seen some strange behavior with correctly spelt parameters not being recognized). Thank you indeed

Kaniz
Community Manager
Community Manager

Hi @Mehdi BEN ABDESSELEM​ , Just a friendly follow-up. Do you still need help, or do the above responses help you find the solution? Please let us know.

mehdi1
New Contributor III

Hi Fatma. There are enough information here. Most importantly, the widget creation instruction doesn't reinitialize the parameter which is passed.

RachelGomez123
New Contributor II

@Mehdi BEN ABDESSELEM​ ,

Steps for Creating a Basic Widget

Step 1: Create a New Project

To create a new project in Android Studio, please refer to How to Create/Start a New Project in Android Studio. We are implementing it for both Java and Kotlin languages.

Step 2: Add the App Widget to the Project

Right-Click on the app, move the cursor to new, find the “Widget” option at the end, and select it.

Specify the required properties for the widget, such as min. Width and height, config file, and preferred language proceed. Files are automatically generated.

Step 3: Install and Run the Code

Install and Run the code on Android Virtual Device (AVD) or a personal device.

Open the widget section of the phone, lookup for a widget with the Application name, select it, and bring it to the home screen.

Try changing the dimensions, and we are done!

This may help you,

Rachel Gomez

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.