Skip to content

Commit

Permalink
feat(jupyter): add utility functions for running in jupyter
Browse files Browse the repository at this point in the history
The utility functions can be helpful both for running trame in the jupyter event loop and for
running trame as a separate jupyter server proxy process. Cookie cutter examples are soon to follow.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
  • Loading branch information
psavery committed Apr 14, 2022
1 parent 614b378 commit f7f96ad
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions trame/jupyter/__init__.py
@@ -0,0 +1,7 @@
from .display import display_iframe
from .proxy import run

__all__ = [
"display_iframe",
"run",
]
15 changes: 15 additions & 0 deletions 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)
12 changes: 12 additions & 0 deletions 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)

0 comments on commit f7f96ad

Please sign in to comment.