Can we pass a dynamic list in SELECT Parameter based on the value entered by user in other parameter
Hi,
I am trying to pass a dynamic list in select parameter (parameter-b) based on the text entered by user in a string parameter (parameter-a). I am not sure how to do this.
I am able to pass a list in select parameter using the following code:
import os
def do(payload, config, plugin_config, inputs):
load_file_list0= [i for i in os.listdir("/location/") if ".out" in i]
choices=[]
for i in load_file_list0:
choices_dir={}
choices_dir["value"]=i
choices_dir["label"]=i
choices.append(choices_dir)
return {"choices": choices}
But I want to do something like this:
def do(payload, config, plugin_config, inputs):
a= get_recipe_config()["parameter-a"]
load_file_list0= [i for i in os.listdir("/location/") if ".out" in i]
choices=[]
for i in load_file_list0:
if a.lower() in i.lower():
choices_dir={}
choices_dir["value"]=i
choices_dir["label"]=i
choices.append(choices_dir)
return {"choices": choices}
Answers
-
Hello,
In order to do dynamic SELECT, you will need to follow https://doc.dataiku.com/dss/latest/plugins/reference/params.html#dynamic-select-using-python
and you cannot use get_recipe_config() but retrieve the configuration from the `config` variable
So for your case it should be something like:def do(payload, config, plugin_config, inputs): a= config["parameter-a"] load_file_list0= [i for i in os.listdir("/location/") if ".out" in i] choices=[] for i in load_file_list0: if a.lower() in i.lower(): choices_dir={} choices_dir["value"]=i choices_dir["label"]=i choices.append(choices_dir) return {"choices": choices}
If you need to react dynamically to a change of parameter-a you will need to use a fully custom form:
https://doc.dataiku.com/dss/latest/plugins/reference/other.html#custom-settings-uiRegards.
Aurelien