-
I'm trying to build a web app using trame with data viz using pyvista. What I'm expecting to get: What I'm actually getting: And this is my code: from trame.app import get_server
from trame.ui.vuetify import SinglePageWithDrawerLayout
from trame.widgets import vuetify
import pyvista as pv
from pyvista.trame.ui import plotter_ui
# -----------------------------------------------------------------------------
# Trame initialization
# -----------------------------------------------------------------------------
pv.OFF_SCREEN = True
server = get_server()
state, ctrl = server.state, server.controller
state.trame__title = "My App"
ctrl.on_server_ready.add(ctrl.view_update)
# -----------------------------------------------------------------------------
# Plotting
# -----------------------------------------------------------------------------
pl = pv.Plotter()
mesh_actor = None
def create_mesh(solid):
global pl, mesh_actor
if mesh_actor is not None:
pl.remove_actor(mesh_actor)
if solid == 'sphere':
mesh_actor = pl.add_mesh(pv.Sphere())
elif solid == 'cube':
mesh_actor = pl.add_mesh(pv.Cube())
pl.reset_camera()
# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------
with SinglePageWithDrawerLayout(server) as layout:
layout.title.set_text(state.trame__title)
with layout.drawer as drawer:
with vuetify.VRow():
btn_save = vuetify.VBtn('SAVE', click=lambda: print('save'), disabled=True)
btn_load = vuetify.VBtn('LOAD', click=lambda: print('load'))
btn_solve = vuetify.VBtn('SOLVE', click=lambda: print('solve'), disabled=True)
btn_snack = vuetify.VBtn("SNACK", click=lambda: vuetify.VSnackbar('hi'))
with vuetify.VRow():
vuetify.VSelect(
label="Choose 3",
v_model=("Choose3", 0),
items=(
"choose3",
[
{"text": "choice 1", "value": 0},
{"text": "choice 2", "value": 1},
{"text": "choice 3", "value": 2},
],
),
)
vuetify.VSelect(
label="Choose 2",
v_model=("Choose2", 0),
items=(
"choose2",
[
{"text": "choice 1", "value": 0},
{"text": "choice 2", "value": 1},
],
),
)
update_bounds = lambda: print(f'Pmin={state.Pmin}, Pmax={state.Pmax}')
with vuetify.VRow():
vuetify.VTextField(label='Text', v_model=('Test','test'))
vuetify.VTextField(label='Min P', v_model=('Pmin', 0), type='number', single_line=True, change=update_bounds)
vuetify.VTextField(label='Max P', v_model=('Pmax', 0), type='number', single_line=True, change=update_bounds)
with layout.toolbar:
vuetify.VSpacer()
vuetify.VBtn("Sphere", click=lambda: create_mesh("sphere"))
vuetify.VBtn("Cube", click=lambda: create_mesh("cube"))
with layout.content:
with vuetify.VContainer(
fluid=True,
classes="pa-0 fill-height",
):
# Use PyVista UI template for Plotters
view = plotter_ui(pl)
ctrl.view_update = view.update
server.start() I'm mostly confused about what's going on inside the drawer, in lines 48-84. Specifically:
Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
jourdain
Apr 21, 2023
Replies: 1 comment 5 replies
-
Welcome to trame!
Then for the last question, you can not create a detached widget (Snackbar) as a callback. The UI should be created once and rely on the shared state to show/hide/enable UI element. with layout:
vuetify.VBtn("ToggleSnack", click="show_snack = !show_snack")
vuetify.VSnackbar("Hello world", v_model=("show_snack", False)) That part is documented here. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
jourdain
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Welcome to trame!
Then for the last question, you can not create a detached widget (Snackbar) as a callback. The UI should be created once and rely on the shared state to show/hide/enable UI element.
In short you are looking at doing something like.