Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jupyter): add utility functions for running in jupyter
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
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .display import display_iframe | ||
from .proxy import run | ||
|
||
__all__ = [ | ||
"display_iframe", | ||
"run", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |