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 

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source