Dynamically passing component as input to another component

Hello KNIME Community,

I’m working on a set of workflows where I have several separate components (A, B, C, D ..), each with its own unique logic and nested sub-components. However, all of these workflows share a common core loop for processing data. The loop logic is identical across all workflows, but each workflow needs to run a different nested sub-component inside the loop.
Instead of duplicating the core loop logic in each of my components, I would like to create a reusable core loop component and dynamically execute different nested sub-components (e.g., nested_component_A, nested_component_B, etc.) depending on the workflow.

My requirements:

I want the core loop to be a separate reusable component that can be used across different workflows/components.
I need to pass the name of the sub-component or sub-component to the core loop and have it execute the corresponding nested logic.

  1. The logic for each sub-component should remain separate (i.e., Component A uses nested_component_A, Component B uses nested_component_B, etc.), but the looping logic should be shared.

Questions:

  • Is it possible to pass a nested sub-component dynamically into a core loop component ?

  • Is there an example or existing solution with shared loops where different sub-components are executed inside the same loop?

I will appreciate any help.
Thanks in advance,
Aleksandra

you can add e.g. a selection or number configuration inside your component. that way you can define from the outside, which switch input you want to go along inside.

but, i would still recommend to split this up into some pre-, main- and post-steps (with the main being your reusable section) if feasible.

Thank you,

Unfortunately in my case, each component is a separate tool, so I cant create logical switches inside, deciding which sub-component to use. I think the only solution would be to pass component as a parameter to another component, but from what I see, this is not possible.

Aleksandra

@AJ1 have you thought about using sub-workflows that you can dynamically call depending o a variable. I think one limitation would be that the ports might have to be the same.

Thank you @mlauber71 . This makes sense, but unfortunately in my case I can’t store any additional workflows or files in any other location than component itself.

Hi @AJ1 ,

I am not 100% sure whether I understand your requirements correctly. Let’s see whether this approach goes in the right direction.

Cheers,

nan

1 Like

@AJ1 maybe you can check this out. I adapted the idea of @nan and created a switch to call different workflow being stored as .knwf files (you can create them elsewhere). Obviously the KNIMW WF will have to have the same number of input and output ports to match. Otherwise, you will have to refresh the port settings once

Settings to store the captured workflow as .knwf file:

Thank you @nan and @mlauber71 , it looks like it’s what I was looking for!

1 Like