Bokeh Test 1

What is this?

This is a test blog to check for statically hosted plots using bokeh. Using bokeh library in python, to make a plot that renders well in a webserver. Then, the contents of the script and the div tags in the webpage are extracted and placed in the markdown file. Now, using pandoc, the markdown file is converted into a full-fledged html that is then used by python Jinja2 to make a webpage. Testing Plots in Bokeh implemented in HTML.

Source Code

import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show
from bokeh.embed import components

# Set up data
N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))

# Set up plot
plot = figure(plot_height=400, plot_width=400, title="my sine wave",
              tools="crosshair,pan,reset,save,wheel_zoom",
              x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

show(plot)
script, div = components(plot)

print(div)
print(script)
# html = file_html(plot, CDN, "my plot")

Output

<script type="text/javascript">
  (function() {
    var fn = function() {
      Bokeh.safely(function() {
        (function(root) {
          function embed_document(root) {
            
          var docs_json = '{"37d7bad3-68c1-414e-b758-d720567f3e22":{"roots":{"references":[{"attributes":
          {"ticker":{"id":"1014","type":"BasicTicker"}},"id":"1017","type":"Grid"},{"attributes":{},
          "id":"1041","type":"BasicTickFormatter"},{"attributes":{},"id":"1026","type":"SaveTool"},
          {"attributes":{"formatter":{"id":"1041","type":"BasicTickFormatter"},"ticker":{"id":"1019",
          "type":"BasicTicker"}},"id":"1018","type":"LinearAxis"},{"attributes":{},"id":"1043",
          "type":"BasicTickFormatter"},{"attributes":{},"id":"1027","type":"WheelZoomTool"},{"attributes":
          {"below":[{"id":"1013","type":"LinearAxis"}],"center":[{"id":"1017","type":"Grid"},{"id":"1022",
          "type":"Grid"}],"left":[{"id":"1018","type":"LinearAxis"}],"plot_height":400,"plot_width":400,
          "renderers":[{"id":"1037","type":"GlyphRenderer"}],"title":{"id":"1003","type":"Title"},"toolbar":
          {"id":"1028","type":"Toolbar"},"x_range":{"id":"1005","type":"Range1d"},"x_scale":{"id":"1009",
          "type":"LinearScale"},"y_range":{"id":"1007","type":"Range1d"},"y_scale":{"id":"1011",
          "type":"LinearScale"}},"id":"1002","subtype":"Figure","type":"Plot"},{"attributes":{},"id":"1019",
          "type":"BasicTicker"},{"attributes":{"text":"my sine wave"},"id":"1003","type":"Title"},
          {"attributes":{"active_drag":"auto","active_inspect":"auto","active_multi":null,
          "active_scroll":"auto","active_tap":"auto","tools":[{"id":"1023","type":"CrosshairTool"},
          {"id":"1024","type":"PanTool"},{"id":"1025","type":"ResetTool"},{"id":"1026","type":"SaveTool"},
          {"id":"1027","type":"WheelZoomTool"}]},"id":"1028","type":"Toolbar"},{"attributes":{},"id":"1044",
          "type":"UnionRenderers"},{"attributes":{"dimension":1,"ticker":{"id":"1019","type":"BasicTicker"}},
          "id":"1022","type":"Grid"},{"attributes":{"callback":null,"end":12.566370614359172},"id":"1005",
          "type":"Range1d"},{"attributes":{},"id":"1045","type":"Selection"},{"attributes":{"data_source":
          {"id":"1001","type":"ColumnDataSource"},"glyph":{"id":"1035","type":"Line"},"hover_glyph":null,
          "muted_glyph":null,"nonselection_glyph":{"id":"1036","type":"Line"},"selection_glyph":null,"view":
          {"id":"1038","type":"CDSView"}},"id":"1037","type":"GlyphRenderer"},{"attributes":{"callback":null,
          "end":2.5,"start":-2.5},"id":"1007","type":"Range1d"},{"attributes":{},"id":"1023",
          "type":"CrosshairTool"},{"attributes":{"source":{"id":"1001","type":"ColumnDataSource"}},
          "id":"1038","type":"CDSView"},{"attributes":{},"id":"1009","type":"LinearScale"},{"attributes":
          {"line_alpha":0.1,"line_color":"#1f77b4","line_width":3,"x":{"field":"x"},"y":{"field":"y"}},
          "id":"1036","type":"Line"},{"attributes":{},"id":"1011","type":"LinearScale"},{"attributes":{},
          "id":"1024","type":"PanTool"},{"attributes":{"formatter":{"id":"1043","type":"BasicTickFormatter"},
          "ticker":{"id":"1014","type":"BasicTicker"}},"id":"1013","type":"LinearAxis"},{"attributes":
          {"line_alpha":0.6,"line_color":"#1f77b4","line_width":3,"x":{"field":"x"},"y":{"field":"y"}},
          "id":"1035","type":"Line"},{"attributes":{},"id":"1025","type":"ResetTool"},{"attributes":{},
          "id":"1014","type":"BasicTicker"},{"attributes":{"callback":null,"data":{"x":
          {"__ndarray__":"AAAAAAAAAABMJ0jGcCqwP0wnSMZwKsA/8jpsKak/yD9MJ0jGcCrQPx8x2vcMNdQ/8jpsKak/2D/FRP5aRUrcP0wnSMZwKuA/NiwR374v4j8fMdr3DDXkPwg2oxBbOuY/8jpsKak/6D/cPzVC90TqP8VE/lpFSuw/rknHc5NP7j9MJ0jGcCrwP8GprNIXLfE/NiwR374v8j+qrnXrZTLzPx8x2vcMNfQ/lLM+BLQ39T8INqMQWzr2P324Bx0CPfc/8jpsKak/+D9nvdA1UEL5P9w/NUL3RPo/UMKZTp5H+z/FRP5aRUr8PzrHYmfsTP0/rknHc5NP/j8jzCuAOlL/P0wnSMZwKgBAhmh6TMSrAEDBqazSFy0BQPvq3lhrrgFANiwR374vAkBwbUNlErECQKqudetlMgNA5e+ncbmzA0AfMdr3DDUEQFlyDH5gtgRAlLM+BLQ3BUDO9HCKB7kFQAg2oxBbOgZAQ3fVlq67BkB9uAcdAj0HQLj5OaNVvgdA8jpsKak/CEAsfJ6v/MAIQGe90DVQQglAof4CvKPDCUDcPzVC90QKQBaBZ8hKxgpAUMKZTp5HC0CLA8zU8cgLQMVE/lpFSgxA/4Uw4ZjLDEA6x2Jn7EwNQHQIle0/zg1ArknHc5NPDkDpivn55tAOQCPMK4A6Ug9AXg1eBo7TD0BMJ0jGcCoQQOlHYYkaaxBAhmh6TMSrEEAkiZMPbuwQQMGprNIXLRFAXsrFlcFtEUD76t5Ya64RQJgL+BsV7xFANiwR374vEkDTTCqiaHASQHBtQ2USsRJADY5cKLzxEkCqrnXrZTITQEfPjq4PcxNA5e+ncbmzE0CCEME0Y/QTQB8x2vcMNRRAvFHzurZ1FEBZcgx+YLYUQPeSJUEK9xRAlLM+BLQ3FUAx1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ut/JdIa67+X/6GXMvrpv4+3GZIQv+i/I1MFrK1q578zLd1BZf7lv0l7+BKre+S/BeEvxgnk4r/NWyBXITnhv9kJU9tK+d6/LruwQrdg278vrwhVM6zXvyPx7QWH39O/xgwd4CX9z78zqYPAmBrIv3iY8JZyH8C/5m2uzrAnsL8HXBQzJqbBvA==","dtype":"float64","shape":[200]}},
          "selected":{"id":"1045","type":"Selection"},"selection_policy":{"id":"1044",
          "type":"UnionRenderers"}},"id":"1001","type":"ColumnDataSource"}],"root_ids":["1002"]},
          "title":"Bokeh Application","version":"1.2.0"}}';
          var render_items = [{"docid":"37d7bad3-68c1-414e-b758-d720567f3e22","roots":
          {"1002":"f7e2854c-5286-4729-a2ce-5c13e9ac7a77"}}];
          root.Bokeh.embed.embed_items(docs_json, render_items);
        
          }
          if (root.Bokeh !== undefined) {
            embed_document(root);
          } else {
            var attempts = 0;
            var timer = setInterval(function(root) {
              if (root.Bokeh !== undefined) {
                embed_document(root);
                clearInterval(timer);
              }
              attempts++;
              if (attempts > 100) {
                console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");
                clearInterval(timer);
              }
            }, 10, root)
          }
        })(window);
      });
    };
    if (document.readyState != "loading") fn();
    else document.addEventListener("DOMContentLoaded", fn);
  })();
</script>

<div class="bk-root" id="f7e2854c-5286-4729-a2ce-5c13e9ac7a77" data-root-id="1002"></div>

Status

It works! A static plot works!