Bokeh widgets including Div, PreText, and Paragraph are not rendering in a jupyter notebook in VS Code or a browser.
Example:
from bokeh.io import show
from bokeh.models import Div
div = Div(text="text")
show(div)
Stack traceback:
Error: Model 'Div' does not exist. This could be due to a widget or a custom model not being registered before first usage.
at Object.s.Models (https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js:163:190)
at Function._instantiate_object (https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js:162:5089)
at Function._instantiate_references_json (https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js:162:5239)
at Function.from_json (https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js:162:8384)
at Object.t.embed_items_notebook (https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js:555:1533)
at embed_document (eval at runCodeHere (vscode-resource://file///Users/brandonlockhart/.vscode/extensions/ms-python.python-2020.5.80290/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:11583), <anonymous>:6:20)
at eval (eval at runCodeHere (vscode-resource://file///Users/brandonlockhart/.vscode/extensions/ms-python.python-2020.5.80290/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:11583), <anonymous>:10:5)
at eval (eval at runCodeHere (vscode-resource://file///Users/brandonlockhart/.vscode/extensions/ms-python.python-2020.5.80290/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:11583), <anonymous>:26:3)
at runCodeHere (vscode-resource://file///Users/brandonlockhart/.vscode/extensions/ms-python.python-2020.5.80290/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:11583)
at t.value (vscode-resource://file///Users/brandonlockhart/.vscode/extensions/ms-python.python-2020.5.80290/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:12015)
That said, things still work fine for me without output_notebook, they just cause the output to be a separate HTML file shown in a new tab (as expected).
The proximate cause of the error is that widget implementations are split in to a separate bokeh-widgets-2.0.2.min.js bundle, and your browser has not loaded this file. But Bokeh always automatically includes extra bundles when they are needed by default, so more information would be necessary to try and understand what is preventing that from happening in your specific situation.
The widgets render on occasion, but I usually have this problem. I guess my browser only sometimes loads bokeh-widgets-2.0.2.min.js, I don’t know why it would not load it. If you have any more ideas about what might be the problem please let me know.
I tried using Safari version 13.1.1 and Firefox version 77.0.1 and am having the same problem. Rendering glyphs from bokeh.plotting always works though.
Any other messages on the JS console? Any information in the browser network debug pane? I’m afraid I’m somewhat at a loss. You could also try using inline resources instead of default loading from CDN.
But what can has been observed is that if a browser first loads BokehJS without the SRI attributes (for any reason), then a subsequent load with them set can fail. This is due to a particular interpretation Chrome’s makes wrt SOP and caching that many people regard as a bug in Chrome. [1] I have not observed or heard of it anywhere but Chrome, though. [2]
There are some spots in the docs that failed to set the SRI hashes, so that made it too easy to trigger this situation for users that viewed the affected pages first. But as of the upcoming release, every place I can think of should be properly setting the SRI attributes, so someone would have to really go out of their way to have them loaded without.
TLDR; all I can suggest right now is to clear cache / force reload or use inline resources.
All the gory details for anyone that wants to see them:
I guess I should add: I am speculating that the above is what is going on in this particular situation. I can’t think of any other reason, because the only way I know that the header could be missing is that it is being loaded out of cache (without it having been set previously when it was put there).
Thanks a lot for the detailed information. It works in Chrome when I clear cache, but it’s not ideal having to do that frequently. I will keep looking into this issue. Thanks!