The resources module provides the Resources class for easily configuring how BokehJS code and CSS resources should be located, loaded, and embedded in Bokeh documents.
Additionally, functions for retrieving Subresource Integrity hashes for Bokeh JavaScript files are provided here.
Some pre-configured Resources objects are made available as attributes.
CDN
load minified BokehJS from CDN
INLINE
provide minified BokehJS from library static directory
CSSResources
The CSSResources class encapsulates information relating to loading or embedding Bokeh client-side CSS.
mode (str) –
how should Bokeh CSS be included in output
See below for descriptions of available modes
version (str, optional) –
what version of Bokeh CSS to load
Only valid with the 'cdn' mode
'cdn'
root_dir (str, optional) –
root directory for loading BokehJS resources
Only valid with 'relative' and 'relative-dev' modes
'relative'
'relative-dev'
minified (bool, optional) – whether CSS should be minified or not (default: True)
root_url (str, optional) –
URL and port of Bokeh Server to load resources from
Only valid with 'server' and 'server-dev' modes
'server'
'server-dev'
The following mode values are available for configuring a Resource object:
'inline' configure to provide entire BokehJS code and CSS inline
'inline'
'cdn' configure to load Bokeh CSS from https://cdn.bokeh.org
https://cdn.bokeh.org
'server' configure to load from a Bokeh Server
'server-dev' same as server but supports non-minified CSS
server
'relative' configure to load relative to the given directory
'relative-dev' same as relative but supports non-minified CSS
relative
'absolute' configure to load from the installed Bokeh library static directory
'absolute'
'absolute-dev' same as absolute but supports non-minified CSS
'absolute-dev'
absolute
Once configured, a Resource object exposes the following public attributes:
css_raw
any raw CSS that needs to be places inside <style> tags
<style>
css_files
URLs of any CSS files that need to be loaded by <link> tags
<link>
messages
any informational messages concerning this configuration
These attributes are often useful as template parameters when embedding Bokeh plots.
JSResources
The Resources class encapsulates information relating to loading or embedding Bokeh Javascript.
How should Bokeh JS be included in output
what version of Bokeh JS to load
root directory for loading Bokeh JS assets
minified (bool, optional) – whether JavaScript should be minified or not (default: True)
URL and port of Bokeh Server to load resources from (default: None)
If None, absolute URLs based on the default server configuration will be generated.
None
root_url can also be the empty string, in which case relative URLs, e.g., “static/js/bokeh.min.js”, are generated.
root_url
'inline' configure to provide entire Bokeh JS and CSS inline
'cdn' configure to load Bokeh JS and CSS from https://cdn.bokeh.org
'server-dev' same as server but supports non-minified assets
'relative-dev' same as relative but supports non-minified assets
'absolute-dev' same as absolute but supports non-minified assets
Resources
The Resources class encapsulates information relating to loading or embedding Bokeh Javascript and CSS.
how should Bokeh JS and CSS be included in output
what version of Bokeh JS and CSS to load
root directory for loading Bokeh JS and CSS assets
minified (bool, optional) – whether JavaScript and CSS should be minified or not (default: True)
js_raw
any raw JS that needs to be placed inside <script> tags
<script>
js_files
URLs of any JS files that need to be loaded by <script> tags
get_all_sri_hashes
Report SRI script hashes for all versions of BokehJS.
Bokeh provides Subresource Integrity hashes for all JavaScript files that are published to CDN for full releases. This function returns a dictionary that maps version strings to sub-dictionaries that JavaScipt filenames to their hashes.
dict
Example
The returned dict will map version strings to sub-dictionaries for each version:
{ '1.4.0': { 'bokeh-1.4.0.js': 'vn/jmieHiN+ST+GOXzRU9AFfxsBp8gaJ/wvrzTQGpIKMsdIcyn6U1TYtvzjYztkN', 'bokeh-1.4.0.min.js': 'mdMpUZqu5U0cV1pLU9Ap/3jthtPth7yWSJTu1ayRgk95qqjLewIkjntQDQDQA5cZ', ... } '1.3.4': { ... } ... }
get_sri_hashes_for_version
Report SRI script hashes for a specific version of BokehJS.
Bokeh provides Subresource Integrity hashes for all JavaScript files that are published to CDN for full releases. This function returns a dictionary that maps JavaScript filenames to their hashes, for a single version of Bokeh.
version (str) – The Bokeh version to return SRI hashes for. Hashes are only provided for full releases, e.g “1.4.0”, and not for “dev” builds or release candidates.
KeyError – if the specified version does not exist
The returned dict for a single version will map filenames for that version to their SRI hashes:
{ 'bokeh-1.4.0.js': 'vn/jmieHiN+ST+GOXzRU9AFfxsBp8gaJ/wvrzTQGpIKMsdIcyn6U1TYtvzjYztkN', 'bokeh-1.4.0.min.js': 'mdMpUZqu5U0cV1pLU9Ap/3jthtPth7yWSJTu1ayRgk95qqjLewIkjntQDQDQA5cZ', 'bokeh-api-1.4.0.js': 'Y3kNQHt7YjwAfKNIzkiQukIOeEGKzUU3mbSrraUl1KVfrlwQ3ZAMI1Xrw5o3Yg5V', 'bokeh-api-1.4.0.min.js': '4oAJrx+zOFjxu9XLFp84gefY8oIEr75nyVh2/SLnyzzg9wR+mXXEi+xyy/HzfBLM', 'bokeh-tables-1.4.0.js': 'I2iTMWMyfU/rzKXWJ2RHNGYfsXnyKQ3YjqQV2RvoJUJCyaGBrp0rZcWiTAwTc9t6', 'bokeh-tables-1.4.0.min.js': 'pj14Cq5ZSxsyqBh+pnL2wlBS3UX25Yz1gVxqWkFMCExcnkN3fl4mbOF8ZUKyh7yl', 'bokeh-widgets-1.4.0.js': 'scpWAebHEUz99AtveN4uJmVTHOKDmKWnzyYKdIhpXjrlvOwhIwEWUrvbIHqA0ke5', 'bokeh-widgets-1.4.0.min.js': 'xR3dSxvH5hoa9txuPVrD63jB1LpXhzFoo0ho62qWRSYZVdyZHGOchrJX57RwZz8l' }
verify_sri_hashes
Verify the SRI hashes in a full release package.
This function compares the computed SRI hashes for the BokehJS files in a full release package to the values in the SRI manifest file. Returns None if all hashes match, otherwise an exception will be raised.
Note
This function can only be called on full release (e.g “1.2.3”) packages.
ValueError – If called outside a full release package
RuntimeError – If there are missing, extra, or mismatched files