Python Extension Development (Labs): View node with output table

Hi all,

using the Python Extension Development API I’m trying to develop a view node which displays a matplotlib plot and returns an output table at the same time.

Unluckily, during execution this results in the following error:

Execute failed: no view could be created for ArrowSourceTable[cols=28, rows=6, batches=1]

Please see the following MWE:

import knime.api as knapi
import knime.extension as knext  # type: ignore[import-untyped]
import matplotlib as mpl
import matplotlib.pyplot as plt


@knext.node(
    name="Plot stuff and return data",
    node_type=knext.NodeType.VISUALIZER,
    category="/community/my-views/,
)
@knext.input_table(
    name="some input", description="blah",
)
@knext.output_view(
    name="my shiny plot", description="also blah"
)
@knext.output_table(
    name="table to return", description="something"
)
class PlotAndReturnTable:
    """Some docstring."""

    def configure(
        self,
        configure_context: knext.ConfigurationContext,
        some_input_schema: knext.Schema,
    ) -> knext.Schema:  # <<<<<<<<<<<<<<<<<<<<<<<<<<<<< how to annotate the return types when there is a view?
        """
        Configure the Python node.

        Parameters
        ----------
        configure_context
            _description_
        some_input_schema
            _description_

        Returns
        -------
        knext.Schema
            _description_
        """
        return some_input_schema

    def execute(
        self,
        exec_context: knext.ExecutionContext,
        some_input_data: knext.Table,
    ) -> tuple[knapi.views.NodeView, knext.Table]:
        """
        Execute node.

        Parameters
        ----------
        exec_context
            _description_
        some_input_data
            _description_

        Returns
        -------
        tuple[knapi.views.NodeView, knext.Table]
            _description_
        """
        # Plot something:
        line_hndls: list[mpl.lines.Line2D] = plt.plot([0, 1], [2, 3])

        return knext.view_matplotlib(), some_input_data

Additional findings:

  • NodeView is not available as part of knime.extensions, but required to correctly annotate types. We need to use knime.api.views.NodeView which is probably not very straightforward to find.
  • Without the output table, the plot is shown correctly. But when I open the plot in a separate window and close it afterwards, the workflow pane turns white and all my nodes are “gone” - at least visually -, forcing me to restart Knime.

I’m using Knime AP 5.8.1 LTS on Linux.

Any idea how to implement/fix this?

Thanks in advance and best regards,

Johannes