diplay code content with bokeh code example

Example: embed Bokeh components to HTML

def _metrics_script_divs(report, metrics):
    cds = figures.construct_metrics_cds(metrics, 'total', index='forecast',
                                        rename=figures.abbreviate)
    data_table = figures.metrics_table(cds)

    # Create initial bar figures
    figures_bar = []
    for num, metric in enumerate(report.metrics):
        fig = figures.bar(cds, metric)
        figures_bar.append(fig)

    # Components for 'total' category. RC - script, (div1, div2) = components((plot1, plot2))
    # Then, return render(request,'filename.html',{'script':script, 'div1':div1, 'div2':div2})
    
    script, (data_table_div, *figures_bar_divs) = components((data_table,
                                                              *figures_bar))

    script_metrics = script
    figures_dict = dict(total=figures_bar_divs)

    # Components for other metrics
    for category in report.categories:
        if category == 'total':
            continue

        script_cat, figures_bar_cat = _loop_over_metrics(report, metrics,
                                                         category)
        script_metrics += script_cat
        figures_dict[category] = figures_bar_cat

    return script_metrics, data_table_div, figures_dict