Skip to content

standalone

Ad-hoc standalone dashboard/widget server for use within Jupyter notebooks.

It runs everything needed to see a dashboard or widget in threads.

This is mostly intended for convenient local use (e.g. by a researcher), or could be adapted for a containerized (in the Docker-sense) environment, e.g. where the user has metador libraries available and can inspect containers.

Do not use this to deploy a widget server backing the widgets on a website.

silence_flask

silence_flask()

Disable HTTP request log (for use inside jupyter).

Source code in src/metador_core/widget/jupyter/standalone.py
32
33
34
35
def silence_flask():
    """Disable HTTP request log (for use inside jupyter)."""
    log = logging.getLogger("werkzeug")
    log.setLevel(logging.ERROR)

run

run(
    *,
    debug: bool = False,
    pn_exts: Optional[List[str]] = None
)

Run ad-hoc standalone server to use widgets and dashboards in a Jupyter notebook.

Source code in src/metador_core/widget/jupyter/standalone.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def run(*, debug: bool = False, pn_exts: Optional[List[str]] = None):
    """Run ad-hoc standalone server to use widgets and dashboards in a Jupyter notebook."""
    global _widget_server, _known_containers, port

    if not debug:
        silence_flask()
    pn.extension(*(pn_exts or DEFAULT_PANEL_EXTS))  # required for panel within jupyter

    port = get_free_port()
    flask_base = f"http://{host}:{port}"

    # prepare bokeh server
    bokeh_port = get_free_port()
    bokeh_base = f"http://{host}:{bokeh_port}"

    def run_bokeh():
        _widget_server.run(
            host=host, port=bokeh_port, allowed_websocket_origin=[f"{host}:{port}"]
        )

    # prepare flask server
    flask_app = Flask(__name__)
    _widget_server.bokeh_endpoint = bokeh_base
    _widget_server.flask_endpoint = flask_base
    flask_bokeh = _widget_server.get_flask_blueprint("widget-api", __name__)
    flask_app.register_blueprint(flask_bokeh)

    def run_flask():
        flask_app.run(host=host, port=port)

    # launch
    t_flask = Thread(target=run_flask)
    t_bokeh = Thread(target=run_bokeh)
    t_flask.start()
    t_bokeh.start()