Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hodakamori opened this issue Oct 30, 2024 · 2 comments

Comments

@hodakamori
Copy link

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
@krish-adi
Copy link
Owner

hey @hodakamori , you can use the get_option method that is here:

def get_option(self, name: str):

i am working on the documentation to make this better. there is also a newer version for this project that is being built here: https://github.com/krish-adi/barfi/tree/migrate-to-react-flow

@hodakamori
Copy link
Author

I am sorry it has taken so long.
And thank you for your comments.

Sorry, what I want to do is to take the information of the node's input and set it to the items of the option.
In other words, in this code, for example, when the columns of In(df) are [“a”, “b”, “c”], items will be [“a”, “b”, “c”], and when the columns are [“dog”, “cat”, “sheep”], items will be [“dog”, “cat”, “sheep”]. This is what we want.

However, the option items is always [“select y”], which is df is None behavior. From what I can see, it seems that the items in block.add_option are determined when the block is added and then do not change dynamically based on the node's connection state.

We would like to create a node where the user uploads a csv file, reads the csv as a dataframe, and then creates a node that selects a specific column and does some processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants