diff --git a/source/__init__.py b/source/__init__.py index 62e18867362..aa0002d947d 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -9,6 +9,7 @@ from .server import status from .server import wait from .server import serve +from .server import widget from .server import __version__ def main(): diff --git a/source/server.py b/source/server.py index cb65d6ed143..3dd35fa1dd1 100755 --- a/source/server.py +++ b/source/server.py @@ -267,7 +267,7 @@ def wait(): _log(True, '\n') stop() -def serve(file, data, address=None, browse=False, verbosity=1): +def serve(file, data=None, address=None, browse=False, verbosity=1): '''Start serving model from file or data buffer at address and open in web browser. Args: @@ -324,3 +324,15 @@ def start(file=None, address=None, browse=True, verbosity=1): A (host, port) address tuple. ''' return serve(file, None, browse=browse, address=address, verbosity=verbosity) + +def widget(address, height=800): + ''' Open address as Jupyter Notebook IFrame. + + Args: + address (tuple, optional): A (host, port) tuple, or a port number. + height (int, optional): Height of the IFrame, Default: 800 + ''' + address = _make_address(address) + url = f"http://{address[0]}:{address[1]}" + IPython = __import__('IPython') # pylint: disable=invalid-name + return IPython.display.IFrame(url, width="100%", height=height)