Generating a Dropdown in a Dataiku App Using the Python Do Function

Mattsco
Dataiker
1 min read 1 0 426

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 six 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.

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

2.png

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

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

 

Labels

?
Share: