Python script node does not visualize the Bokeh library output

Lately I got it working:
Python:

from json import dumps

from bokeh.plotting import figure
from bokeh.embed import json_item

#-----------------------------------------------
# do something with bokeh
plot = figure(width = 800, height = 450)
plot.circle([1,2], [3,4])
#-----------------------------------------------


# export the plot to json to Knime variable
item_text = dumps(json_item(plot))
flow_variables['json'] = item_text

# get the bokeh version as Knime variable
import bokeh
flow_variables['bokeh_version']=bokeh.__version__

and the Generic JavaScript View connected via a variable Port

//based on https://forum.knime.com/t/generic-javascript-view-with-bokeh/15210/2
// Function to load css file of Bokeh
function loadCss(url) {
    var link = document.createElement("link");
    link.type = "text/css";
    link.rel = "stylesheet";
    link.href = url;
    document.getElementsByTagName("head")[0].appendChild(link);
}

// Needed to load the bokeh scripts with require.js
requirejs.config({
	paths: {
		bokeh: "https://cdn.pydata.org/bokeh/release/bokeh-$${Sbokeh_version}$$.min",
		bokehApi: "https://cdn.pydata.org/bokeh/release/bokeh-api-$${Sbokeh_version}$$.min"
	},
	shim: {
		bokeh: {
			exports: "Bokeh"
		},
		bokehApi: {
			deps: ["bokeh"]
		}
	}
});

// Inside this function Bokeh is available
require(["bokeh", "bokehApi"], function (Bokeh) {

// Function to load css file of Bokeh
loadCss("https://cdn.pydata.org/bokeh/release/bokeh-$${Sbokeh_version}$$.min.css");

//-----------Begin of Bokeh ------------------
var item_text= '$${Sjson}$$';
item = JSON.parse(item_text);
Bokeh.embed.embed_item(item, "my_bokeh_plot");
//-----------End of Bokeh------------------
});

//Create the Bokeh HTML element 
var div = document.createElement('DIV');
div.setAttribute('id', 'my_bokeh_plot');
document.body.append(div);
2 Likes