Bokeh – Embedding Plots and Apps in this Bokeh Embedding Plots and Apps and data in the form of standalone documents as well as Bok applications can be embedded in HTML documents.
A standalone document is a Bokeh plot or document not backed by a Bokeh server. The interactions in such a plot are purely in the form of custom JS and not Pure Python callbacks.
Such documents contain Python callbacks that run on the server. Bokeh plot is obtained by the file_html() function.
from bokeh.plotting import figure from bokeh.resources import CDN from bokeh.embed import file_html fig = figure() fig.line([1,2,3,4,5], [3,4,5,2,3]) string = file_html(plot, CDN, "my plot")
The return value of the file_html() function may be saved as an HTML file or may be used to render through URL routes in the Flask app.
In the case of a standalone document, its JSON representation can be obtained by the json_item() function.
from bokeh.plotting import figure from bokeh.embed import file_html import json fig = figure() fig.line([1,2,3,4,5], [3,4,5,2,3]) item_text = json.dumps(json_item(fig, "myplot"))
This output can be used by the Bokeh.embed.embed_item function on a webpage −
item = JSON.parse(item_text); Bokeh.embed.embed_item(item);
The server_document() function accepts URL parameter. If it is set to ‘default’, the default URL http://localhost:5006/ will be used.
from bokeh.embed import server_document script = server_document("http://localhost:5006/sliders")
The server_document() function returns a script tag as follows −
<script src="http://localhost:5006/sliders/autoload.js?bokeh-autoload-element=1000&bokeh-app-path=/sliders&bokeh-absolute-url=https://localhost:5006/sliders" id="1000"> </script>
Next Topic – Click Here
Pingback: Bokeh - Exporting Plots - Adglob Infosystem Pvt Ltd