Hi All,
I’m the creator of trame and I would like to improve its support within the Jupyter world. Trame by nature tend to be great for creating standalone web application of any kind. And having such application work locally, remotely, on HPC, in the cloud or within Jupyter is quite powerful.
So my goal here is to provide another backend that would rely on pyviz_comms but I would love if someone could point me to some simple usage of it via Panel (or else) code base.
In the meantime, I’m going through the code, trying to extract how things get setup on the Python and JS side…
Thanks for any pointer you could provide…
Seb
Bonus: trame intro for Jupyter users
Otherwise if you want to have fun and see what it looks like within Jupyter, you can run the following in a cell assuming you did pip install trame
.
The example below rely on vtk.js for the rendering and the widgets are provided by Vuetify.
from trame.app import get_server, jupyter
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify, vtk as vtk_widgets
server = get_server()
state, ctrl = server.state, server.controller
with SinglePageLayout(server) as layout:
with layout.content:
with vuetify.VContainer(fluid=True, classes="pa-0 fill-height"):
with vtk_widgets.VtkView() as view:
ctrl.view_reset_camera = view.reset_camera
with vtk_widgets.VtkGeometryRepresentation():
vtk_widgets.VtkAlgorithm(
vtk_class="vtkConeSource",
state=("{ resolution }",),
)
with layout.toolbar:
vuetify.VSpacer()
vuetify.VSlider(
v_model=("resolution", 6),
min=3,
max=60,
step=1,
hide_details=True,
style="max-width: 300px;",
)
with vuetify.VBtn(icon=True, click=ctrl.view_reset_camera):
vuetify.VIcon("mdi-crop-free")
jupyter.show(server)
And if you want to create another UI for that same server/app, you add the following in the cell below
from trame.ui.vuetify import VAppLayout
with VAppLayout(server, template_name="control"):
vuetify.VSlider(
v_model=("resolution", 6),
min=3,
max=60,
step=1,
hide_details=True,
classes="my-3",
)
jupyter.show(server, ui="control", height=60)
And if you want to react to a change with resolution by calling a function. You can do the following.
@state.change("resolution")
def on_change(resolution, **kwargs):
print(f"cone resolution is {resolution}")
And you can also set a value yourself by doing the following
with state:
state.resolution = 10
Enjoy!