Multiple SELECT parameters using getChoicesFromPython ?
Hi,
I'm currently writing the parameters in my recipe's JSON. I would like to add 2 SELECT choices, both created via python but with different methods. However, I only see one field (paramsPythonSetup) to insert my python script's name. If I try to implement 2 Do functions in it, both SELECT parameters display the choice list corresponding to the last Do function
So... How can I write 2 python codes to generate 2 choices lists in one parameters' JSON ?
Thx for your help
Best Answer
-
Hi,
You will only need 1 function do, and then inside it you do a check on the payload parameter to define which SELECT choice you are dealing with.
Something like this:
def do(payload, config, plugin_config, inputs):
if payload.get('parameterName') == 'parameter2':
choices = [
{ "value" : "val1", "label" : 'value of parameter2 -1'},
{ "value" : "val2", "label" : "Value of parameter 2 - 2"}
]
return {"choices": choices}if payload.get('parameterName') == 'parameter3':
choices = [
{ "value" : "val1", "label" : "Value of parameter 3 - 1"},
{ "value" : "val2", "label" : "Value of parameter 3 - 2"}
]
return {"choices": choices}
Answers
-
Awesome, thank you
-
@duphan
, this is amazing (and it doesn't seem to common knowledge within Dataiku itself as I had a discussion about exactly end of last year).It would be great if this could be added as an example to the official plugin dev documentation!