Custom Bokeh Model from documentation raises exception
See original GitHub issueALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)
Bokeh: 1.4.0 Python: 3.7.4 Jupyter: 1.0.0 OS: Windows 8.1 Browser: Chrome
Description of expected behavior and the observed behavior
I’m trying to learn how to create custom bokeh models. I started out trying the Custom model in https://docs.bokeh.org/en/latest/docs/user_guide/extensions.html. But it raises the below exception.
Expected: It works without exception Actual: Exception
Complete, minimal, self-contained example code that reproduces the issue
I have the file custom.ipynb
from bokeh.core.properties import Instance, String
from bokeh.io import output_file, show
from bokeh.layouts import column
from bokeh.models import HTMLBox, Slider
class Custom(HTMLBox):
__implementation__ = "custom.ts"
text = String(default="Custom text")
slider = Instance(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)
and the file custom.ts
in the same folder
import { HTMLBox, HTMLBoxView } from "models/layouts/html_box"
import { div } from "core/dom"
import * as p from "core/properties"
export class CustomView extends HTMLBoxView {
connect_signals(): void {
super.connect_signals()
// Set BokehJS listener so that when the Bokeh slider has a change
// event, we can process the new data.
this.connect(this.model.slider.change, () => {
this.render()
this.invalidate_layout()
})
}
render(): void {
// BokehjS Views create <div> elements by default, accessible as
// ``this.el``. Many Bokeh views ignore this default <div>, and instead
// do things like draw to the HTML canvas. In this case though, we change
// the contents of the <div>, based on the current slider value.
super.render()
this.el.appendChild(div({
style: {
padding: '2px',
color: '#b88d8e',
backgroundColor: '#2a3153',
},
}, `${this.model.text}: ${this.model.slider.value}`))
}
}
export class Custom extends HTMLBox {
slider: { value: string }
// The ``__name__`` class attribute should generally match exactly the name
// of the corresponding Python class. Note that if using TypeScript, this
// will be automatically filled in during compilation, so except in some
// special cases, this shouldn't be generally included manually, to avoid
// typos, which would prohibit serialization/deserialization of this model.
static __name__ = "Custom"
static init_Custom(): void {
// If there is an associated view, this is typically boilerplate.
this.prototype.default_view = CustomView
// The this.define() block adds corresponding "properties" to the JS model.
// These should normally 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. Any time the JS type system is not
// yet as complete, you can use ``p.Any`` as a "wildcard" property type.
this.define<Custom.Props>({
text: [p.String],
slider: [p.Any],
})
}
}
Stack traceback and/or browser JavaScript console output
Compilation failed:
custom.ts:13:33 - error TS2339: Property 'slider' does not exist on type 'HTMLBox'.
13 this.connect(this.model.slider.change, () => {
~~~~~~
custom.ts:32:26 - error TS2339: Property 'text' does not exist on type 'HTMLBox'.
32 }, `${this.model.text}: ${this.model.slider.value}`))
~~~~
custom.ts:32:46 - error TS2339: Property 'slider' does not exist on type 'HTMLBox'.
32 }, `${this.model.text}: ${this.model.slider.value}`))
~~~~~~
custom.ts:55:21 - error TS2702: 'Custom' only refers to a type, but is being used as a namespace here.
55 this.define<Custom.Props>({
~~~~~~
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (12 by maintainers)
Top Results From Across the Web
How do I create and use a custom Bokeh Model in Panel?
Hi I'm trying to learn some of the more advanced features of Bokeh/ Panel in order to eventually contribute a PyDeck/ Deck.gl panel....
Read more >Source code for bokeh.model
[docs]def get_class(view_model_name): ''' Look up a Bokeh model class, ... Raises: KeyError, if the model cannot be found Example: .. code-block:: python ...
Read more >Bokeh: Models must be owned by only a single document
It may be because of conflicting objects that has the same name. you need to create completely new objects every time.
Read more >bokeh.model — CAVE 1.4.1 documentation
The only exception made is if one of the models has a custom ... be useful when querying the document to retrieve specific...
Read more >Classification — pycaret 2.3.5 documentation - Read the Docs
a custom CV generator object compatible with scikit-learn. ... When set to 'ignore', will skip the model with exceptions and continue. If 'raise' ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If this is in the notebook you will need to call
output_notebook
again after the custom extension is defined. That is what causes the extension definition to exist on the JS side in the notebook.On Sunday, January 19, 2020, Marc Skov Madsen notifications@github.com wrote:
@bryevdv running the example from docs failed for me in two environments with latest nodejs v14.16.0 with the same error as was posted here. Not in a notebook. Just python file and starting the server with
bokeh serve
. It does work with the modified version posted. I also tried to build the extension, but that also failed. When I create a directory and simply runbokeh init
+bokeh build
I get