Hi, 

Is it possible to create linked drop down menus where you link to multiple values at once. it works fine if you link the values by defining separate drop down menus (like below) but is it possible to add all four RCPs to the 'when = ' part of one drop down (the users should be able to select all the same future time periods of the four RCPs) or should I repeat the same input drop down separately for the four RCPs?

@ct.input.dropdown('RCP',
label ='experiment', link=True,
values= ['rcp8_5', 'rcp6_0, 'rcp4_5', 'rcp2_6', 'historical'],
)

@ct.input.dropdown('time',
label ='30 year period', when = 'historical',
values= hist_dict.keys(),
)

@ct.input.dropdown('time',
label ='30 year period', when = 'rcp8_5' ,
values= fut_dict.keys(),
)

@ct.input.dropdown('time',
label ='30 year period', when = 'rcp6_0' ,
values= fut_dict.keys(),
)

etc.

6 Comments

  1. Dear Joreen,

    If I understand your question well you should be able to solve your issue by passing a dictionary to link which maps the different input values to another set of values.


    @ct.input.dropdown('RCP',
    label ='experiment', link={'rcp8_5': 1, 'rcp6_0': 1, 'rcp4_5': 1, 'rcp2_6': 1, 'historical': 2},
    values= ['rcp8_5', 'rcp6_0, 'rcp4_5', 'rcp2_6', 'historical'],
    )

    @ct.input.dropdown('time',
    label ='30 year period', when = 2,
    values= hist_dict.keys(),
    )

    @ct.input.dropdown('time',
    label ='30 year period', when = 1,
    values= fut_dict.keys(),
    )


    Let me know if this is clear enough.

    Vivien

  2. Hi Vivien, 


    Thank you for the quick response. I tried your solution but I get an error. The setup of the drop downs in the code below gives this error:  TypeError: Wrong type for rules dictionary.

    The code works when I create a drop down for every rcp in turn but not while parsing the dictionary,


    @ct.input.dropdown('temp',
    label= 'temporal aggregation',
    link=True,
    values=['10_day', 'season', 'annual'] )

    @ct.input.dropdown('RCP',
    label ='experiment', link={'rcp8_5':1, 'rcp4_5':1, 'rcp2_6':1,'historical':2},
    values= ['rcp8_5', 'rcp4_5', 'rcp2_6', 'historical'],
    )

    @ct.input.dropdown('var',
    label='Variable', when='10_day',
    values=variable_dict.keys(),
    )

    @ct.input.dropdown('var',
    label='Variable', when = 'annual',
    values=variable_dict2.keys(),
    )

    @ct.input.dropdown('var',
    label='Variable', when = 'season',
    values=variable_dict3.keys(),
    )

    @ct.input.dropdown('time',
    label ='30 year period', when = 2,
    values= hist_dict.keys(),
    )

    @ct.input.dropdown('time',
    label ='30 year period', when = 1,
    values= fut_dict.keys(),
    )





    1. If you share the full workflow, or at least part of it that can run independently I can test it directly.

      As a quick test try to use strings instead of integers for the mapping:

      @ct.input.dropdown('RCP',
      label ='experiment', link={'rcp8_5': '1', 'rcp6_0': '1', 'rcp4_5': '1', 'rcp2_6': '1', 'historical': '2'},
      values= ['rcp8_5', 'rcp6_0, 'rcp4_5', 'rcp2_6', 'historical'],
      )

      @ct.input.dropdown('time',
      label ='30 year period', when = '2',
      values= hist_dict.keys(),
      )

      @ct.input.dropdown('time',
      label ='30 year period', when = '1',
      values= fut_dict.keys(),
      )

  3. Hi Vivien,

    I still get the error with strings.

    Can you see the code through this link? https://cds.climate.copernicus.eu/toolbox-editor/2867/save_code-atq78


    Joreen

  4. Great, It works for me too now.  I must have made some mistake in the changes before.

    Thanks for all the help!