Python script node does not visualize the Bokeh library output

I am trying to integrate this Python script in KNIME:

It is an interactive python visualization of clusters using Bokeh library. In a regular environment, I execute it with a command line:
“bokeh serve -show clustering”.

If I try to embed a Python Script with the code, I only get status “the python3Command is controlled by a variable”.

However, if I am trying a much simpler code in Python Script node, like this, the visualization opens with no issues in an external browser:

from bokeh.plotting import figure, output_file, show

# Basic plotting
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output to static HTML file

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness
p.line(x, y, legend_label="Temp.", line_width=2)

# show the results


What is the best way to integrate a complex Python/Bokeh application into the KNIME flow?

Hallo @fbagirov,

could you maybe share your example, so I can have a look at it. The sentence “The python3Command is controlled by a variable” is just simply telling you that you are passing a flow variable to the python3Command to overwriting your inputs. Can you check the Flow Variables Tab and maybe remove this? Or did you set this Flow Variable on purpose?
Did you try to execute your script? Did you get any errors?


Hi @fbagirov

I solved it by storing the bokeh app script/folder in the workflow data area, calling[sys.executable,"-m","bokeh", "serve", "--port", "5100", flow_variables['App path']
in a Python node and afterwards make a Generic Javascript View embed the served HTML from the server running in the background with sth like this:

var body = document.getElementsByTagName('body')[0];
var address = "http://localhost:5100"; 
var html = "<iframe src=\""+ address +"\" height=\"1000px\" width=\"100%\"></iframe>";
body.innerHTML = html;

P.S.: Make sure to include a way to stop your Bokeh server (i.e. onExit or with an extra button).


1 Like

The Bokeh documentation explains a way of creating a JSON configuration in Python and do the plotting in Javascript.
This sounds like a good way of integrating Python-configured Bokeh-plots in a Generic Javascript View in KNIME. But I couldn’t get it working.

In Python I created a flow variable containing the JSON-content like:

import pandas as pd
import json
from bokeh.plotting import figure
from bokeh.embed import json_item

p = figure(), 2)
flow_variables['json'] = json.dumps(json_item(p, "myplot"))

But the to lines of code in Javascript from the Bokeh documentation are not enough to get the view working. Could somebody provide an example, to get that working?