Beginner example needed: @knext.output_view

Hi, Im trying to learn how to create plugins, playing with examples at the moment, but for some reason i am not able to use @knext.output_view example. I tried code below, but node is not visible in knime - other examples work well - enviroment setup should be fine:

# from typing import List # Not sure what this line is for - it was in the example of python extension guide
import knime.extension as knext
import seaborn as sns   # installed through "pixi add seaborn", ran "pixi install" to make sure that it is installed


@knext.node(name="My Node", node_type=knext.NodeType.VISUALIZER, icon_path="icons/icon.png", category="/") # changed icon path to reflect example code structure
@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()

       

Im not that interested in seaborn library - im more interested if it is plausible to display HTML with some tables, plausible images? Maybe someone has a simple working example?

Hello @HQ_Best_QH ,

Firstly, apologies for the late reply.

I think you need to run plt.show() to render the view before calling the view helper function. Maybe this is the issue. However, failure to observe the node to appear in KNIME explorer could be due to some error in parsing of the extension. Unfortunately, I cannot assist further without seeing the logs. Does it happens for all the view nodes?

For the html based views: you can display html by dynamically rendering the html structure on the python side and returning it in execute method as follows:

return knext.view(html)

or if you want to enable the html view for reporting, use with a can_be_used_in_report flag

return knext.view_html(html)

You can refer to this example for better understanding.

I am assuming that you also came across the API document for reference.

Let me know, if you have further questions :slight_smile:

Thank you
Best,
Ali

1 Like

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