diff --git a/trame/jupyter/__init__.py b/trame/jupyter/__init__.py new file mode 100644 index 00000000..2d8cee8c --- /dev/null +++ b/trame/jupyter/__init__.py @@ -0,0 +1,7 @@ +from .display import display_iframe +from .proxy import run + +__all__ = [ + "display_iframe", + "run", +] diff --git a/trame/jupyter/display.py b/trame/jupyter/display.py new file mode 100644 index 00000000..4a82c0f5 --- /dev/null +++ b/trame/jupyter/display.py @@ -0,0 +1,15 @@ +from IPython import display + + +def display_iframe(src, **kwargs): + """Convenience method to display an iframe for the given url source""" + + # Set some defaults. The kwargs can override these. + # width and height are both required. + iframe_kwargs = { + "width": "100%", + "height": 600, + **kwargs, + } + iframe = display.IFrame(src=src, **iframe_kwargs) + return display.display(iframe) diff --git a/trame/jupyter/proxy.py b/trame/jupyter/proxy.py new file mode 100644 index 00000000..dc441259 --- /dev/null +++ b/trame/jupyter/proxy.py @@ -0,0 +1,12 @@ +from .display import display_iframe + + +def run(name, **kwargs): + """Run and display a Jupyter server proxy process with the given name + + Note that the proxy process must be registered with Jupyter by setting + the `jupyter_serverproxy_servers` entrypoint in its setup.py or setup.cfg + file. + """ + src = f"/{name}" + return display_iframe(src, **kwargs)