def init_notebook_plotting(offline=False): """Initialize plotting in notebooks, either in online or offline mode.""" display_bundle = {"text/html": _wrap_js(_js_requires(offline=offline))} display(display_bundle, raw=True) logger.info("Injecting Plotly library into cell. " "Do not overwrite or delete cell.") init_notebook_mode()
def render_report_elements( experiment_name: str, html_elements: List[str], header: bool = True, offline: bool = False, notebook_env: bool = False, ) -> str: """Generate Ax HTML report for a given experiment from HTML elements. Uses Jinja2 for template. Injects Plotly JS for graph rendering. Example: :: html_elements = [ h2_html("Subsection with plot"), p_html("This is an example paragraph."), plot_html(plot_fitted(gp_model, 'perf_metric')), h2_html("Subsection with table"), pandas_html(data.df), ] html = render_report_elements('My experiment', html_elements) Args: experiment_name: the name of the experiment to use for title. html_elements: list of HTML strings to render in report body. header: if True, render experiment title as a header. Meant to be used for standalone reports (e.g. via email), as opposed to served on the front-end. offline: if True, entire Plotly library is bundled with report. notebook_env: if True, caps the report width to 700px for viewing in a notebook environment. Returns: str: HTML string. """ # combine CSS for report and plots css = _load_css_resource() + _load_plot_css_resource() return ( _get_jinja_environment() .get_template(REPORT_ELEMENT_TEMPLATE) .render( experiment_name=experiment_name, css=css, js_requires=_js_requires(), html_elements=html_elements, headfoot=header, notebook_env=notebook_env, ) )