Inquiry about "Create a New Python based KNIME Extension"

Hello.

I was wondering how to create a view node by using this code in document below:
I have successfully created a simple input/output node, but I keep failing to create a chart node.
I would appreciate it if someone could help me.

from typing import List
import knime.extension as knext
import seaborn as sns


@knext.node(name="My Node", node_type=knext.NodeType.VISUALIZER, icon_path="icon.png", category="/")
@knext.input_table(name="Input Data", description="We read data from here")
@knext.output_view(name="My pretty view", description="Showing a seaborn plot")
class MyViewNode:
    """
    A view node

    This node shows a plot.
    """

    def configure(self, config_context, input_table_schema)
        pass

    def execute(self, exec_context, table):
        df = table.to_pandas()
        sns.lineplot(x="x", y="y", data=df)
        return knext.view_seaborn()

        # If the node outputs tables, the output view must
        # be the last element of the return value
        #
        # output_table = knext.from_pandas(df)
        # return output_table, knext.view_seaborn()
        #
        # For multiple table outputs use
        # return output_table_1, output_table_2, knext.view_seaborn()

Hi @hhkim,

There is a small typo, just put a colon “:” after the function definition. This should resolve the issue.

def configure(self, config_context, input_table_schema):
        pass

While passing the input to the node, make sure you have data columns named x and y.

Note: I have asked internally to update the document.

Best,
Keerthan

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.