Survey banner
Switching to Dataiku - a new area to help users who are transitioning from other tools and diving into Dataiku! CHECK IT OUT

Generating a dropdown in a Dataiku App using the python do function

1 min read 4 0 2,253

Sometimes you want to dynamically generate a custom dropdown in your application.
It could be using the values from a dataset column or using the 6 last month's values from today.

You can actually do this using the "edit project variable" tile of a Dataiku application.
Click on "Use custom UI" below the input for auto-generated controls, you'll see you have an input to add a python code.

The python function should look like this:

def do(payload, config, plugin_config, inputs):
  choices = [
    { "value" : "val1", "label" : "Value 1"},
    { "value" : "val2", "label" : "Value 2"}
  return {"choices": choices}

Note: If you load a dataset from it, don't forget to mention the project key as each app instance has its own project key.

Then in the auto-generated controls, you must specify the choices has been generated from the python:

    "type": "SELECT",
    "name": "variable_name",
    "getChoicesFromPython": true

You can use SELECT or MULTISELECT for the types.

Check these screenshots to see an example where I wanted to update a project variable to filter a dataset according to one of the country codes available in the input dataset.

Fig 1: You use a filter recipe, filtering on columns using a project variable value.


Fig 2: Use the custom UI in Edit project variable tile of a Dataiku App to write the python do function.

Fig 3: That’s it you have made an App where the dropdown to select the country is generated from a dataset.