Embed "Bokeh created html file" into Flask "template.html" file
Question: I have a web application written in Python - Flask. When the user fill out
some settings in one of the pages (POST Request), my controller calculates
some functions and plot an output using Bokeh with following command and then
I redirect to that HTML page created by Bokeh.

    
    
    output_file("templates\\" + idx[j]['name'] + ".html", title = "line plots")
    TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"
    p = figure(tools=TOOLS, x_axis_label = 'time', y_axis_label = 'L', plot_width = 1400, plot_height = 900)
    

All of my HTML pages extends my "Template.HTML" file except the Bokeh
generated ones. My question is how can automatically modify Bokeh generated
HTML files to also extends my template.html file? This way I have all my nav-
bar & jumbotron on top of the Bokeh html files.

    
    
      {% extends "template.html" %}
      {% block content %}
    
      <Bokeh.html file>
    
      {% endblock %}
    


Answer: You don't want to use `output_file` in this situation. Bokeh has a function
specifically for embedding into HTML templates in web apps,
`bokeh.embed.component`, demonstrated in the
[quickstart](http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html#components)
and [tutorial](http://nbviewer.ipython.org/github/bokeh/bokeh-
notebooks/blob/master/tutorial/05%20-%20sharing.ipynb).

    
    
    from bokeh.embed import components
    script, div = components(plot)
    return render_template('page.html', script=script, div=div)
    
    
    
    <body>
    {{ div|safe }}
    {{ script|safe }}
    </body>
    

[Here is a complete, runnable example that that shows how to use this with
Flask.](https://github.com/bokeh/bokeh/tree/master/examples/embed/simple)

