Bokeh 0.13 with python 3.6 (anaconda) 64bit on Win10.
I tried using the example from bokeh/examples/embed/embed_multiple.py to embed bokeh components into a static html page and it works.
However, when I add CustomJS interactions to the components, only the first one correctly renders in the browser.
The other components are still there but somehow aren’t rendered correctly.
The example code is:
import io
from jinja2 import Template
from bokeh.embed import components
from bokeh.resources import INLINE
from bokeh.util.browser import view
from bokeh.layouts import column
from bokeh.models import CustomJS
from bokeh.models.widgets import Toggle
from bokeh.core.properties import Int
from bokeh.util.compiler import CoffeeScript
class TechToggle(Toggle):
implementation = CoffeeScript("""
import {Toggle, ToggleView} from “models/widgets/toggle”
import * as p from “core/properties”
export class TechToggleView extends ToggleView
render: () →
super()
export class TechToggle extends Toggle
type = “TechToggle”
default_view = TechToggleView
@define {
techid: [ p.Int, 0 ]
}
“”")
techid = Int(default=0)
buttonstates = [0,0]
toggle0 = TechToggle(techid=0)
toggle1 = TechToggle(techid=1)
#toggles = [toggle0,toggle1]
toggles = {0:toggle0, 1:toggle1}
togglecallback0 = CustomJS(args=dict(toggles=toggles), code="""
console.log(cb_obj.active)
console.log(toggles)
console.log(cb_obj)
if (cb_obj.active == true) {
toggles[1].disabled=true;
} else {
toggles[1].disabled=false;
}
“”")
toggle0.callback = togglecallback0
togglecallback1 = CustomJS(args=dict(toggles=toggles), code="""
console.log(cb_obj.active)
console.log(toggles)
console.log(cb_obj)
if (cb_obj.active == true) {
toggles[0].disabled=true;
} else {
toggles[0].disabled=false;
}
“”")
toggle1.callback = togglecallback1
layout = column(toggle0, toggle1)
plots = {‘Red’: toggle0, ‘Blue’: toggle1}
script, div = components(plots)
template = Template(’’’
Bokeh Scatter Plots{{ resources }}
{{ script }}
.embed-wrapper { width: 50%; height: 400px; margin: auto; }{% for key in div.keys() %}
{{ div[key] }}
{% endfor %}
‘’’)
resources = INLINE.render()
filename = ‘embed_multiple.html’
html = template.render(resources=resources,
script=script,
div=div)
with io.open(filename, mode=‘w’, encoding=‘utf-8’) as f:
f.write(html)
view(filename)
I’ll try and see if the other templating examples can make this work.
What seems to trigger this is the inclusion of the components as args in CustomJS.
Thanks