<aside> 💡 Part of the Dataland Learning Roadmap

</aside>

Objective

This guide walks through how to:

  1. Add a button to a Dataland table (via the UI or from module.yaml)
  2. Write and deploy a Dataland worker that runs in response to button clicks, and writes back the results into the table

We’ll walk through an example from scratch where clicking a button on a row fetches the current weather for a user-supplied location. The code of the end state of this example is here: https://github.com/dataland-io/dataland-examples/tree/main/button-example

See a GIF of the outcome below:

CleanShot 2022-11-21 at 20.30.27.gif

Prerequisites

Instructions

Add a button to a Dataland table

You have two options:

Option 1 — via the UI: You can add a button column to a table using the Dataland UI, just by clicking Add column. However, you won’t be able to do this for tables who have already been declared in module.yaml (and thus have schemas enforced by Dataland's table controller if autoMigrate is true).

Option 2 — via module.yaml: If you have a table already declared in module.yaml, then you can add a new button column by adding another YAML block. The get_weather column in green text is an example of this. Then, run the command dataland deploy on your workspace, and you’ll see a new button column in your table.

tables:
  - tableName: weather_table
    autoMigrate: true
    columnDescriptors:
      # Input column whose values will be args to API call
      - columnName: location
        dataType: string

      # Button column 
      - columnName: get_weather
        dataType: int32
        columnAnnotations:
          dataland.io/column-display-config: |
            {
              "type": "button",
              "label": "Fetch the weather!",
              "theme": "blue"
            }

      # Column to store result of API call
      - columnName: weather_result
        dataType: string

      # Column to store timestamp of API call
      - columnName: checked_at
        dataType: string

Write a worker that responds to button clicks

These steps below will recreate the example weather fetching worker. You can see the end-state here: https://github.com/dataland-io/dataland-examples/blob/main/button-example/src/getWeather.ts