Widgets

Daipe widgets are cross-platform meaning the same interface works on both Databricks and Jupyter Lab as well as when running a .py file as a script from CLI.

Available since

  • databricks-bundle=^1.1.2 - for usage in Databricks
  • jupyter-bundle=^1.1.1 - for usage in Jupyter Lab
  • daipe-core=^1.1.1 - for usage in CLI

Imports

from daipecore.widgets.Widgets import Widgets
from datalakebundle.imports import *

Usage

widgets.add_text(name: str, default_value: str = "", label: str = None)

Creates a text widget

Parameters:

  • name : str - unique identifier of the widget
  • default_value : str, default "" - default value of the widget, optional
  • label : str, default "" - label of the widget, optional

Example:

@notebook_function()
def create_text_widget(widgets: Widgets):
    widgets.add_text("text_widget", "Hello", "Test widget")

widgets.add_select(self, name: str, choices: list, default_value: str, label: str = None)

Creates a select/dropdown widget

Parameters:

  • name : str - unique identifier of the widget
  • choices : list - the choices to select
  • default_value : str, default "" - default value of the widget, optional
  • label : str, default "" - label of the widget, optional

Example:

@notebook_function()
def create_select_widget(widgets: Widgets):
    widgets.add_select("select_widget", ["option1", "option2", "option3"], "option1", "Test widget")

widgets.add_multiselect(self, name: str, choices: list, default_value: str, label: str = None)

Creates a multiselect widget

Parameters:

  • name : str - unique identifier of the widget
  • choices : list - the choices to select
  • default_value : str, default "" - default value of the widget, optional
  • label : str, default "" - label of the widget, optional

Example:

@notebook_function()
def create_multiselect_widget(widgets: Widgets):
    widgets.add_multiselect("multiselect_widget", ["option1", "option2", "option3"], "option1", "Test widget")

widgets.get_value(self, name: str)

Returns a value from a widget

Parameters:

  • name : str - unique identifier of the widget

Example:

@transformation(load_df)
def get_widget_value(df: DataFrame, widgets: Widgets):
    value = widgets.get_value("text_widget")  # value: "Hello"
    return df.filter(f.col("col") == value)

widgets.remove(self, name: str)

Deletes a widget

Parameters:

  • name : str - unique identifier of the widget

Example:

@notebook_function()
def remove_widget(widgets: Widgets):
    widgets.remove("text_widget")

widgets.remove_all(self)

Deletes all widgets

Example:

@notebook_function()
def remove_widget(widgets: Widgets):
    widgets.remove_all()