Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/vitepress/guide/jupyter/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ Let's review the various available options
from module import App

app = App()
await app.ui.ready
app.ui.iframe_builder = "..." # <= force an iframe builder
app.ui
await app.display_cell()
```

| iframe_builder | URL | Default if |
Expand All @@ -24,6 +23,7 @@ app.ui
| jupyter-extension | ENV(TRAME_JUPYTER_WWW)/servers/{server.name}/ | Extension loaded and available |
| jupyter-hub | ENV(JUPYTERHUB_SERVICE_PREFIX)proxy/{server.port}/ | If JUPYTERHUB_SERVICE_PREFIX exist |
| jupyter-hub-host | ENV(JUPYTERHUB_SERVICE_PREFIX)proxy/{host}:{server.port}/ | Never a default |
| google-colab | google.colab.kernel.proxyPort({server.port}) | If COLAB_RELEASE_TAG or COLAB_BACKEND_VERSION exist |

The selection can also be done via the __TRAME_IFRAME_BUILDER__ environment variable.

Expand Down
55 changes: 51 additions & 4 deletions docs/vitepress/guide/jupyter/intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Trame and Jupyter Lab

A trame application, while working in standalone fashion, can also be imported inside Jupyter and displayed within a notebook.
To make that possible, the user will need to be able to import and instantiate such application in a Jupyter context. Then, the user will need to have access to the layout (ui) of that application so it can be displayed in the notebook flow.
A trame application, while working in standalone fashion, can also be imported inside Jupyter and displayed within a
notebook.

To make that possible, the user will need to be able to import and instantiate such application in a Jupyter context.
Then, the user will need to have access to the layout (ui) of that application so it can be displayed in the notebook
flow.

## Simple example

Expand All @@ -17,7 +21,6 @@ source .venv/bin/activate # => Linux / Mac

# Install dependencies
pip install trame trame-vtk trame-vuetify # adding vuetify + vtk.js for demo app
pip install setuptools # used in trame-vuetify but not always available nowaday
pip install jupyterlab
```

Expand All @@ -37,11 +40,55 @@ from trame.app.demo import Cone
app = Cone()

# Put the UI into the resulting cell
app
await app.display_cell(height="600px")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mention the 2 options. Returning the app is neat, but we should mention that it does not work with collab and the more explicit await is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the doc to add the alternative syntaxes as an example. Let me know what you think!

```

```{note}
Alternatively, the application instance can be returned and used directly to display the cell in JupyterLab.
However this syntax will not work when used in google-colab's context where an explicit call to `display_cell` is
expected.
```

```python
# Alternative syntax to instantiate and display the app in JupyterLab cell
Cone()

# The previous call is equivalent to instantiating the application, followed by a direct `repr` call
app = Cone()
app # This line will trigger the display of the app in the cell

# However, for cross-compatibility with google-colab it's preferable to use the display_cell method
app = Cone()
await app.display_cell()
```


This should look like

![Cone in Jupyter](/assets/images/jupyter/jupyter-cone.png)

If you want [more examples using the same code, you can look at that binder example repository](https://github.com/Kitware/trame-binder).

## google-colab

Starting with trame-client v3.13.1 trame is compatible with google-colab's Jupyter environment.

To run trame in google-colab, start by installing trame's dependencies.

```jupyter
%%capture --no-stderr

!pip install -q --upgrade trame trame-vtk trame-vuetify
```

The application can then be displayed using the `display_cell` method.

```python
from trame.app.demo import Cone

# Create new application instance
app = Cone()

# Put the UI into the resulting cell
await app.display_cell(height="600px")
Comment thread
jourdain marked this conversation as resolved.
```
12 changes: 5 additions & 7 deletions docs/vitepress/guide/jupyter/sample-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ When a trame application is laid out like above, you can just run the following
from module import App

app = App()
await app.ui.ready
app.ui
await app.display_cell(height="600px")
```

And in case you want to have a second instance independent of the first one, you can do

```python
app2 = App('v2')
await app2.ui.ready
app2.ui

await app2.display_cell(height="600px")
```

## Changing application state
Expand Down Expand Up @@ -69,8 +68,7 @@ with DivLayout(server, 'a', height=30) as ui_a:
style="width: 100%;",
)

await ui_a.ready
ui_a
await ui_a.display_cell()
```

Then you can create more ui on the same server
Expand All @@ -83,7 +81,7 @@ with DivLayout(server, 'b', height=30) as ui_b:
)
html.Span("{{ slider_a }} / 2 = {{ result }}", style="margin-left: 2rem")

ui_b
await ui_b.display_cell()
```

![Multi-UI in Jupyter](/assets/images/jupyter/multi-ui.png)
Loading