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:ย 

Notebook dropdown widget

Sagar1
New Contributor III

I have created a dropdown (say B) in my notebook whose input depend on dropdown( say B). So if select some value in dropdown A, it corresponding value appears in B dropdown & i'm selecting one amongst it. Now if i change the value in dropdown A, then Value in drop B is also changing but the one previously selected is still there. Is there any way if i cab refresh that dropdown.

3 REPLIES 3

Sagar1
New Contributor III

Hi @Kaniz Fatmaโ€‹ ,

โ€‹

I tried and explored all the documents before raising question here, but none of them has solution for my problem. There after i relaize that like remove widget we must have reset widget option as well, which will reset it to its default value, as we are providing it during its creation.โ€‹

Sagar1
New Contributor III

Yes, @Kaniz Fatmaโ€‹  I would like to raise a request on ideas portal.โ€‹

nic_paul24
New Contributor II

If the previously selected value of B is not meant to be in the list of values for newly selected dropdown A value, then you could set a default value (ie: 'No selection') that the B dropdown should have when first created. In a method to define how you create B, check if current B value is not valid for A, if it is not then create the dropdown widget with the default value.

If the value of B makes sense also when dropdown A changes, try to find a way to figure out if A changed. For example write the code to create B in a cell where you also call dbutils.widgets.get(A). This will run the cell when A changes, then create B with the default value. When running the cell that checks if A changed, also write create_B (input_values, 'No selection').

It's complicated, but follow the logic and you will get there.

def create_B (input_values, default):
   values = [value for value in input_values]
  if (default not in values):
     default = 'No selection'
  if ('No selection' not in values):
     values.insert(0, 'No selection')
 dbutils.widgets.dropdown('widget B', default, values)

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