title: Deploying a Bokeh server with Flask
body: <p>Trying to get a simple working panel/bokeh server on my web server.</p>
  <p>I have embed.html</p>
  <pre><code>&lt;head&gt;
    {{ resources|safe }}
  &lt;/head&gt;
  
  
  {% block content %}
  &lt;h1&gt;Plot should be here.&lt;/h1&gt;
  &lt;div&gt;
    {{ div|safe }}
    {{ script|safe }}
  &lt;/div&gt;
  
  {% endblock %}
  </code></pre>
  <p>panel_test.py</p>
  <pre><code>def sine(frequency, phase, amplitude):
      xs = np.linspace(0, np.pi*4)
      return hv.Curve((xs, np.sin(frequency*xs+phase)*amplitude)).options(width=800)
  
  if __name__ == '__main__':
      ranges = dict(frequency=(1, 5), phase=(-np.pi, np.pi), amplitude=(-2, 2), y=(-2, 2))
      dmap = hv.DynamicMap(sine, kdims=['frequency', 'phase', 'amplitude']).redim.range(**ranges)
      pn.serve(dmap, port=5006, allow_websocket_origin=[&quot;localhost:5000&quot;], show=False,threaded=True)
  </code></pre>
  <p>main_test.py</p>
  <pre><code>app = Flask(__name__)
  application=app
  # locally creates a page
  @app.route('/')
  def index():
  
      script = server_document(url='localhost:5006')
      # print(script)
      # use the script in the rendered page
      print(&quot;Session Pulled!&quot;, datetime.now())
      print(script)
      return render_template(&quot;embed.html&quot;, script=script)
      
  
  if __name__ == '__main__':
      # runs app in debug mode
      app.run(port=5000, debug=True)
  </code></pre>
  <p>After firing up panel_test.py I get confirmation that the panel is running</p>
  <p>Which is great.  Then running my main_test.py on my server it seems to communcate with localhost but I get a webpage with just 'Plot should be here' (as expected) and nothing else.  Upon looking at the source code it looks like render_template has inserted the 'script' code (See below) but does not seem to be rendering the images:</p>
  <pre><code>  var xhr = new XMLHttpRequest()
    xhr.responseType = 'blob';
    xhr.open('GET', &quot;localhost:5006/autoload.js?bokeh-autoload-element=1002&amp;bokeh-app-path=/localhost:5006&amp;bokeh-absolute-url=localhost:5006&quot;, true);
    
    xhr.onload = function (event) {
      var script = document.createElement('script'),
      src = URL.createObjectURL(event.target.response);
      script.src = src;
      document.body.appendChild(script);
    };
  xhr.send();
  </code></pre>
  <p>Has anyone encountered this?</p>