how can write def do(payload, config, plugin_config, inputs): code ?

Jawaher
Jawaher Registered Posts: 1

to interactive with the UI of macros using "type": "SELECT" in "type": "OBJECT_LIST"?

{
"name": "test",
"label": "test.",
"type": "OBJECT_LIST",
"itemLabel": "test", "subParams": [ { "name": "obj", "label": "Object", "type": "SELECT", "forceReloadOnValueChange": true, "getChoicesFromPython": true } ] }

Answers

  • MollyHarras
    MollyHarras Registered Posts: 2 ✭✭✭

    Hi @Jawaher! The do() function should return a dictionary that looks something like this:

    {"choices": [
      {"value": "opt1", "label": "Option 1"},
      {"value": "opt2", "label": "Option 2"}
    ]
    

    Your code will likely generate the array in the dictionary. Let's say we want our dropdown to list the numbers 0 through 9. The do() function would go something like this:

    def do(payload, config, plugin_config, inputs):
      
      if payload.get("parameterName") == "interface_select_name":
        choices_array = [{"value": str(i), "label": f"Number {str(i)}"} for i in range(10)]
    
      return {"choices": choices_array}
    

    The if condition ensures we're only creating the list of choices for the relevant parameter in our interface. The value "interface_select_name" should be replaced by whatever the name of the dropdown parameter is.

    The choices_array variable uses list comprehension to create an array of dictionaries that will display text like "Number 9" to the end user but will return the associated value "9" to the plugin code for use in executing the plugin. This section of the code may utilize user-selected values in other interface parameters or may grab data from the input datasets, among other things, to create the list of choices.

    Finally, the return statement places the choices_array in the required dictionary format for Dataiku.

    For more information, see here: https://doc.dataiku.com/dss/latest/plugins/reference/params.html#dynamic-select-using-python

    Thank you!

    Molly Harras
    Aimpoint Digital
    molly.harras@aimpointdigital.com

Setup Info
    Tags
      Help me…