Skip to content

How do I dynamically change the item type in add_option type=“select”? #38

Open
@hodakamori

Description

@hodakamori

I think block.add_option can set the type of element to select as follows.
How can I receive this item candidate from node's input?

I would like to create a node that receives a data frame and selects a specific column within that data frame, as in the code example below. However, after the items are first rendered, they seem to remain the same regardless of the node's connection state.

def xy_selecter() -> Block:
    block = Block(name="XY Selecter")

    block.add_input(name="In(df)")
    block.add_output(name="Out(X, df)")
    block.add_output(name="Out(y, df)")

    df = block.get_interface(name="In(df)")
    if df is None:
        items = ["select y"]
    else:
        items = df.columns
    block.add_option(
        name="select y",
        type="select",
        items=items,
    )

    def compute_func(self: Any) -> None:
        df = self.get_interface(name="In(df)")
        y_col = self.get_interface(name="select y")
        y = df[y_col]
        X = df[df.columns != y_col]
        self.set_interface(name="Out(X, df)", value=X)
        self.set_interface(name="Out(y, df)", value=y)

    block.add_compute(compute_func)

    return block

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions