Dynamic Array automatic updated OptionField choices

Hi all,

I’m experimenting with an Dynamic Array in which an user can select a certain material, colour and finish. The combination of these three inputs returns a set of variables required for further calculations.

To streamline this array I want to enable only the options that work for that given material. I want to do this based on information stored in a Pandas DataFrame. The reason for this workflow is rather simple as Material A has colour X, Y and Z, while Material B only has X, Y and another colour named D. I use the same logic for the finish column.

Now I’m using the following code, yet I cannot use the value under ‘Material’ for my pandas selection statement. Currently all possible options for colour and finish are shown, meaning for material A, B and C combined.

This is my code:

with df_path.open() as f:
    df= pd.read_csv(df_path)

class Parametrization(ViktorParametrization):
    array= DynamicArray("Material properties")
    array.name= TextField("Element name")
    array.material = OptionField(
    array.colour= OptionField(
        options=list(df[df['Material'] == array.colour].loc[:,'Colour'].unique())
    array.finish= OptionField(
        options=list(df[(df['Material'] == array.material) & (df['Colour'] == array.colour)].loc[:,'Finish'].unique())

I already tested the following methods: OptionListElement and a function to get the right options (User input, fields and buttons - Options & selections | VIKTOR Documentation). Both don’t work for a DynamicArray.

I tried this, but it won’t work:

options=list(df.loc[df['Material'] == RowLookup('material'), 'Colour'].unique()),

Hi Jelle,

Your choice for using a DataFrame as a base for parameter fields and option lists in a DynamicArray raises the level of complexity very quickly.

As you found out, the option to use a RowLookup doesn’t work as this function is only meant to use for visibility or min/max purposes.

As an alternative to what you’re trying to do with the RowLookup I’d say try to use callback functions. But in this specific case, using a DynamicArray, that also does not yield a satisfactory result I’m afraid.

So I suspect it would be easier to have a look at some alternatives, begging the questions:

  • Why are you using a DataFrame? (Could you code in a static dict for example?)-
  • How much variability is there in the size of the DataFrame? (if it always contains the same number of materials etc. that would give us some other options)
  • Is the DynamicArray the best option here? (maybe a Table could also suffice?

TLDR: What you are asking is a dynamic optionlist in a DynamicArray which as of yet is not possible. I have added your use-case to our internal issue tracker where this feature request is already being tracked. If any developments follow from it I will update you on those here.

In the meantime I’m afraid you are going to have to look for different methods of providing your users with the possible options.

p.s. I will also edit this post to be a feature request for findability.

1 Like

I will test some alternatives and share the results, hopefully I can find some way around the issue. Thanks for the elaborate answer!