elements by default, accessible as @$el.
# Many Bokeh views ignore this default
, and instead do things
# like draw to the HTML canvas. In this case though, we change the
# contents of the
, based on the current slider value.
@$el.html("
#{ @model.text }: #{ @model.slider.value }
")
@$('h1').css({ 'color': '#686d8e', 'background-color': '#2a3153' })
class Custom extends LayoutDOM.Model
# If there is an associated view, this is boilerplate.
default_view: CustomView
# The ``type`` class attribute should generally match exactly the name
# of the corresponding Python class.
type: "Custom"
# The @define block adds corresponding "properties" to the JS model. These
# should basically line up 1-1 with the Python model class. Most property
# types have counterparts, e.g. bokeh.core.properties.String will be
# p.String in the JS implementation. Where the JS type system is not yet
# as rich, you can use p.Any as a "wildcard" property type.
@define {
text: [ p.String ]
slider: [ p.Any ]
}
# This is boilerplate. Every implementation should export a Model
# and (when applicable) also a View.
module.exports =
Model: Custom
View: CustomView
"""
# This JavaScript implememtation is then attached to a corresponding Python Bokeh model:
# In[24]:
from bokeh.core.properties import String, Instance
from bokeh.models import LayoutDOM, Slider
class Custom(LayoutDOM):
__implementation__ = JS_CODE
text = String(default="Custom text")
slider = Instance(Slider)
# Then the new model can be used seamlessly in the same way as any built-in Bokeh model:
# In[25]:
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import Slider
slider = Slider(start=0, end=10, step=0.1, value=0, title="value")
custom = Custom(text="Special Slider Display", slider=slider)
layout = column(slider, custom)
show(layout)
# In[ ]: