- Bokeh - Discussion
- Bokeh - Useful Resources
- Bokeh - Quick Guide
- Bokeh - Developing with JavaScript
- Bokeh - WebGL
- Bokeh - Extending Bokeh
- Bokeh - Embedding Plots and Apps
- Bokeh - Exporting Plots
- Bokeh - Using Bokeh Subcommands
- Bokeh - Server
- Bokeh - Adding Widgets
- Bokeh - Customising legends
- Bokeh - Styling Visual Attributes
- Bokeh - Plot Tools
- Bokeh - Layouts
- Bokeh - Filtering Data
- Bokeh - ColumnDataSource
- Bokeh - Pandas
- Bokeh - Annotations and Legends
- Bokeh - Axes
- Bokeh - Setting Ranges
- Bokeh - Specialized Curves
- Bokeh - Wedges and Arcs
- Bokeh - Rectangle, Oval and Polygon
- Bokeh - Circle Glyphs
- Bokeh - Area Plots
- Bokeh - Plots with Glyphs
- Bokeh - Basic Concepts
- Bokeh - Jupyter Notebook
- Bokeh - Getting Started
- Bokeh - Environment Setup
- Bokeh - Introduction
- Bokeh - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Bokeh - Embedding Plots and Apps
Plots and data in the form of standalone documents as well as Bokeh apppcations can be embedded in HTML documents.
Standalone document is a Bokeh plot or document not backed by Bokeh server. The interactions in such a plot is purely in the form of custom JS and not Pure Python callbacks.
Bokeh plots and documents backed by Bokeh server can also be embedded. Such documents contain Python callbacks that run on the server.
In case of standalone documents, a raw HTML code representing a Bokeh plot is obtained by file_html() function.
from bokeh.plotting import figure from bokeh.resources import CDN from bokeh.embed import file_html fig = figure() fig.pne([1,2,3,4,5], [3,4,5,2,3]) string = file_html(plot, CDN, "my plot")
Return value of file_html() function may be saved as HTML file or may be used to render through URL routes in Flask app.
In case of standalone document, its JSON representation can be obtained by json_item() function.
from bokeh.plotting import figure from bokeh.embed import file_html import json fig = figure() fig.pne([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);
Bokeh apppcations on Bokeh Server may also be embedded so that a new session and Document is created on every page load so that a specific, existing session is loaded. This can be accomppshed with the server_document() function. It accepts the URL to a Bokeh server apppcation, and returns a script that will embed new sessions from that server any time the script is executed.
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/spders")
The server_document() function returns a script tag as follows −
<script src="http://localhost:5006/spders/autoload.js?bokeh-autoload-element=1000&bokeh-app-path=/spders&bokeh-absolute-url=https://localhost:5006/spders" id="1000"> </script>Advertisements