Example #1
0
def build_and_dump_explainer(explainer_config, dashboard_config=None):
    explainer = build_explainer(explainer_config)

    click.echo(
        f"explainerdashboard ===> Calculating properties by building Dashboard..."
    )
    if dashboard_config is not None:
        ExplainerDashboard.from_config(explainer, dashboard_config)
    elif Path(explainer_config['explainer']['dashboard_yaml']).exists():
        click.echo(
            f"explainerdashboard ===> Calculating properties by building Dashboard from {explainer_config['explainer']['dashboard_yaml']}..."
        )
        dashboard_config = yaml.safe_load(
            open(str(explainer_config['explainer']['dashboard_yaml']), "r"))
        ExplainerDashboard.from_config(explainer, dashboard_config)
    else:
        click.echo(f"explainerdashboard ===> Calculating all properties")
        explainer.calculate_properties()

    click.echo(
        f"explainerdashboard ===> Saving explainer to {explainer_config['explainer']['explainerfile']}..."
    )
    if (dashboard_config is not None
            and explainer_config['explainer']['explainerfile'] !=
            dashboard_config['dashboard']['explainerfile']):
        click.echo(
            f"explainerdashboard ===> Warning explainerfile in explainer config and dashboard config do not match!"
        )
    explainer.dump(explainer_config['explainer']['explainerfile'])
    return
Example #2
0
def launch_dashboard_from_yaml(dashboard_config,
                               no_browser,
                               port,
                               no_dashboard=False):
    if isinstance(dashboard_config,
                  (Path, str)) and str(dashboard_config).endswith(".yaml"):
        config = yaml.safe_load(open(str(dashboard_config), "r"))
    elif isinstance(dashboard_config, dict):
        config = dashboard_config
    else:
        raise ValueError(
            f"dashboard_config should either be a .yaml filepath or a dict!")

    if not Path(config['dashboard']['explainerfile']).exists():
        click.echo(
            f"explainerdashboard ===> {config['dashboard']['explainerfile']} does not exist!"
        )
        click.echo(
            f"explainerdashboard ===> first generate {config['dashboard']['explainerfile']} with explainerdashboard build"
        )
        return

    click.echo(
        f"explainerdashboard ===> Building dashboard from {config['dashboard']['explainerfile']}"
    )

    db = ExplainerDashboard.from_config(config)

    if port is None:
        port = config['dashboard']['params']['port']
        if port is None:
            port = 8050
        click.echo(
            f"explainerdashboard ===> Setting port to {port}, override with e.g. --port 8051"
        )

    if not no_browser and not os.environ.get("WERKZEUG_RUN_MAIN"):
        click.echo(
            f"explainerdashboard ===> launching browser at {f'http://localhost:{port}/'}"
        )
        webbrowser.open_new(f"http://localhost:{port}/")

    click.echo(f"explainerdashboard ===> Starting dashboard:")
    if not no_dashboard:
        db.run(port)
    return