Plugin UI related question

rishabh1994
rishabh1994 Partner, Registered Posts: 7 Partner

Hi team,

I am actually trying to have two dropdown lists in my plugin UI , one of which is suppose to display the columns of one input data and the other is suppose to display that columns common in both the input datasets.

Thanks to @EliasH
,I was able to display the columns of input data using the

"paramsPythonSetup": "computechoices.py",
    "params": [
        {
            
           
            
            "name": "column_select",
            "label":"Select Additional columns",
            "type": "MULTISELECT",
            "getChoicesFromPython": true
            
            
        }

in the json file and adding the following python code named "computechoices.py" in a folder named resource in the plugin folder :

import dataiku

def do(payload, config, plugin_config, inputs):
for i in inputs:
if i['role'] == "additional_input": #Must match what you've named the role to be
input_dataset = i['fullName']

dataset = dataiku.Dataset(input_dataset)
schema = dataset.read_schema()
schema_columns = [col['name'] for col in schema]

choices = []
for c in range(len(schema_columns)):
choices.append({"value": schema_columns[c], "label": schema_columns[c]})
return {"choices": choices}

However, I am not sure how to go about to generate the second list , should I add another code in the resource folder,if so, what should the syntax in the json look like.I wonder if there can be multiple "paramsPythonSetup": arguments in json, each pointing to a different python code.

Would appreciate any ideas..

Thanks!

Best Answer

  • fchataigner2
    fchataigner2 Dataiker Posts: 355 Dataiker
    edited July 17 Answer ✓

    for a parameters in your component like

        "paramsPythonSetup":"do.py",
        "params": [
            {
                "name": "param1",
                "label": "Parameter 1",
                "type": "SELECT",
                "getChoicesFromPython": true
            },
            {
                "name": "param2",
                "label": "Parameter 2",
                "type": "SELECT",
                "getChoicesFromPython": true
            }
        ],
    

    your python helper can be

    def do(payload, config, plugin_config, inputs):
        if payload.get('parameterName') == 'param1':
            return {"choices": [{"value":"1", "label":"One"}, {"value":"2", "label":"Two"}]}
        else:
            return {"choices": [{"value":"3", "label":"Three"}, {"value":"4", "label":"Four"}]}

Answers

  • fchataigner2
    fchataigner2 Dataiker Posts: 355 Dataiker

    Hi,

    the payload parameter to the `do()` function will contain information about what initiated it, in particular you should get a `parameterName` field to indicate which name of the dropdown the `do()` will populate.

  • rishabh1994
    rishabh1994 Partner, Registered Posts: 7 Partner

    Hi @fchataigner2
    ,

    Thanks for the prompt reply,

    so is the "parameterName" field suppose to be specified in the json file?

    Also, can you please elaborate how I can write two do () statements each returning a different "choices" list for the two dropdowns and then specifying which list is called for different named dropdowns in json.

    Sorry for being redundant , I am new to this.

    Thanks

  • rishabh1994
    rishabh1994 Partner, Registered Posts: 7 Partner

    Thanks, works perfectly!

Setup Info
    Tags
      Help me…