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?
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?
I solved it by storing the bokeh app script/folder in the workflow data area, calling
subprocess.run([sys.executable,"-m","bokeh", "serve", "--port", "5100", flow_variables['App path']
in a Python node and afterwards make a
var body = document.getElementsByTagName('body');
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).
In Python I created a flow variable containing the JSON-content like:
import pandas as pd
from bokeh.plotting import figure
from bokeh.embed import json_item
p = figure()
flow_variables['json'] = json.dumps(json_item(p, "myplot"))