Views
function knime.scripting.io.view(obj) → NodeView
Return a best-effort NodeView for obj.
The function attempts, in order, to
- match obj to one of the dedicated helper functions listed below, or
- fall back to the object's IPython
_repr_*_methods (_repr_html_,_repr_svg_,_repr_png_,_repr_jpeg_).
Images - SVG, PNG, JPEG, matplotlib, seaborn - are exported with a static snapshot and therefore show up in Reports of the KNIME Reporting Extension outputs automatically. All other supported objects (HTML strings, Plotly figures, etc.) are not supported in reports by default. To enable them in reports, use the view_html function and set the can_be_used_in_report flag.
Special view implementations
The input must match one of the following patterns:
- HTML
strstarting with"<!DOCTYPE html>". Must be self-contained; external links open in a browser. - SVG
strcontaining valid<svg … xmlns="…">markup. - PNG
bytesbeginning with the PNG magic number. - JPEG
bytesbeginning0xFFD8FFand ending0xFFD9. - Matplotlib
matplotlib.figure.Figureinstance. - Plotly
plotly.graph_objects.Figureinstance.
Parameters
- obj :
Any— The object to visualise.
Raises
- ValueError — If no suitable helper or
_repr_*_method is found.
function knime.scripting.io.view_matplotlib(fig = None, format = 'png') → NodeView
Create a NodeView that displays a matplotlib figure and is report-ready out of the box.
The figure is exported as a PNG or SVG (controlled by format). If fig is None, the current active figure is used. The figure is then closed so it should not be modified afterwards.
Because a static image is always supplied, the helper sets can_be_used_in_report=True automatically, allowing the view to appear in reports generated by the KNIME Reporting Extension without additional JavaScript.
Parameters
- fig :
matplotlib.figure.Figure— Figure to render. Defaults to the current figure. - format :
(png, svg)— Output format embedded in the HTML snippet.
Raises
- ImportError — If matplotlib is not available.
- TypeError — If the figure is not a matplotlib figure.
function knime.scripting.io.view_seaborn() → NodeView
Create a NodeView that shows the current active seaborn figure and is report-ready out of the box.
The function simply forwards to view_matplotlib because seaborn charts are regular matplotlib figures under the hood.
As a static image is always embedded, the helper sets can_be_used_in_report=True automatically, so the view can be included in reports generated by the KNIME Reporting Extension without any extra JavaScript.
Raises
- ImportError — If matplotlib is not available.
function knime.scripting.io.view_plotly(fig) → NodeView
Create a view showing the given plotly figure.
The figure is displayed by exporting it as an HTML document.
To be able to synchronize the selection between the view and other KNIME views the customdata of the figure traces must be set to the RowID.
Parameters
- fig :
plotly.graph_objects.Figure— A plotly figure object which should be displayed.
Raises
- ImportError — If plotly is not available.
- TypeError — If the figure is not a plotly figure.
Examples
python
>>> fig = px.scatter(df, x="my_x_col", y="my_y_col", color="my_label_col",
... custom_data=[df.index])
... node_view = view_plotly(fig)function knime.scripting.io.view_html(html: str, svg_or_png: Optional[Union[str, bytes]] = None, render_fn: Optional[Callable[[], Union[str, bytes]]] = None, can_be_used_in_report = False) → NodeView
Create a NodeView that displays the given HTML document.
The document must be self-contained and must not reference external resources. Links to external resources will be opened in an external browser.
Parameters
- html :
str— A string containing the HTML document. - svg_or_png :
str or bytes— A rendered representation of the HTML page. Either a string containing an SVG or a bytes object containing a PNG image. - render_fn :
callable— A callable that returns an SVG or PNG representation of the page. - can_be_used_in_report :
bool— Indicates whether this view will appear in a report generated by the KNIME Reporting Extension. Only set the flag toTruewhen you provide the view to the knime-ui-extension-service ReportingService.
function knime.scripting.io.view_svg(svg: str) → NodeView
Create a NodeView that shows an SVG and is report-ready out of the box.
Parameters
- svg :
str— SVG markup (must include the<svg ...>root element with the XML namespace declaration).
function knime.scripting.io.view_png(png: bytes) → NodeView
Create a NodeView that shows a PNG image and is report-ready out of the box.
Parameters
- png :
bytes— Raw PNG data.
function knime.scripting.io.view_jpeg(jpeg: bytes) → NodeView
Create a NodeView that shows a JPEG image and is report-ready out of the box.
Parameters
- jpeg :
bytes— Raw JPEG data.
function knime.scripting.io.view_ipy_repr(obj) → NodeView
Create a NodeView by using the IPython _repr_*_ function of the object.
Tries to use:
_repr_html__repr_svg__repr_png__repr_jpeg_
in this order.
Parameters
- obj :
object— The object which should be displayed.
Raises
- ValueError — If no view could be created for the given object.
class knime.scripting.io.NodeView
A wrapper that embeds a visualisation in KNIME Analytics Platform.
Notes
Do not instantiate NodeView directly—use one of the helper functions (view, view_html, view_svg, view_png, view_jpeg, …).
Parameters
- html :
str— Self-contained HTML snippet that renders the interactive view inside KNIME AP. - svg_or_png :
str | bytes | None— Static SVG or PNG/JPEG bytes handed to the Reporting engine when a report is generated. If None, the value is produced lazily via render_fn. - render_fn :
Callable[[], str | bytes] | None— Callback that returns svg_or_png on-demand. - can_be_used_in_report :
bool— Set True to signal that this view can be embedded in a report produced by the KNIME Reporting Extension. _ Image helpers (view_svg,view_png,view_jpeg,view_matplotlib, …) turn the flag on automatically because they always provide the image to the Reporting engine. _ HTML helpers leave the flag False by default. Only enable it when the view's JavaScript sends a static representation to the ReportingService usingreportingService.setReportingContent(...). If you are not in control of the JavaScript or cannot ensure this, keep the flag False so the view is omitted from the report instead of breaking it.