-
I have an application where I am continually calculating data and I want to have the view display this as it happens in an animation. As a simple example below, I tried rotating a cylinder (instead of streaming new data). Here is my example code to demonstrate the kind of thing I would like. But it gives the error about the event loop shown at the bottom of this post. Is this possible with trame and if so how? Thanks.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The solution below is just using the async event loop. If you need a tread you need to sync the request with the event loop like we do here import time
import asyncio
import pyvista as pv
from pyvista.trame.ui import plotter_ui
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
pv.OFF_SCREEN = True
server = get_server()
state, ctrl = server.state, server.controller
cyl = pv.Cylinder(resolution=8, direction=(0, 1, 0))
pl = pv.Plotter()
pl.background_color = (0.1, 0.2, 0.4)
pl.add_mesh(cyl, name="cyl")
keep_rotate = True
@ctrl.add_task("on_server_ready")
async def _update(**kwargs):
await asyncio.sleep(5)
while keep_rotate:
cyl.rotate_x(10.0, inplace=True)
cyl.rotate_y(-5.0, inplace=True)
pl.add_mesh(cyl, name="cyl")
pl.render()
ctrl.view_update()
await asyncio.sleep(0.5)
with SinglePageLayout(server) as layout:
with layout.content:
view = plotter_ui(pl)
ctrl.view_update = view.update
server.start() I pushed that example here for reference. |
Beta Was this translation helpful? Give feedback.
The solution below is just using the async event loop. If you need a tread you need to sync the request with the event loop like we do here