
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/09_trame/a_getting_started.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorial_09_trame_a_getting_started.py>`
        to download the full example code. or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorial_09_trame_a_getting_started.py:


Getting started
~~~~~~~~~~~~~~~

Getting started with PyVista and Trame

.. GENERATED FROM PYTHON SOURCE LINES 9-13

.. code-block:: Python


    import pyvista as pv
    from pyvista import examples


.. GENERATED FROM PYTHON SOURCE LINES 14-30

PyVista's Jupyter backend is powered by **Trame**. So by default you are
using trame without knowing it.

By default PyVista is serving you a micro trame application that let you
toggle between **Remote** and **Local** rendering along with some various
options to configure your visualization.

**First try the Remote/Local rendering toggle and notice the differences**

.. raw:: html

   <div class="alert alert-block alert-info">
   Look at the orientation axis between the 2 rendering modes.
   </div>

One sends images generated on the server side while the other is sending geometry to vtk.js.

.. GENERATED FROM PYTHON SOURCE LINES 30-33

.. code-block:: Python

    dataset = examples.download_lucy()
    dataset.plot(smooth_shading=True, color="white")


.. GENERATED FROM PYTHON SOURCE LINES 34-37

Building applications with PyVista and Trame

Now, let's build a simple application that updates the mesh color with the click of a button.

.. GENERATED FROM PYTHON SOURCE LINES 37-70

.. code-block:: Python


    import random

    from pyvista.plotting.colors import hexcolors
    from pyvista.trame.ui import get_viewer
    from trame.ui.vuetify3 import SinglePageLayout
    from trame.widgets import vuetify3 as v3

    plotter = pv.Plotter()
    actor = plotter.add_mesh(dataset)
    viewer = get_viewer(plotter)
    view = None


    def change_color() -> None:
        actor.prop.color = random.choice(list(hexcolors.keys()))  # noqa: S311
        view.update()


    # Create UI
    with SinglePageLayout(viewer.server) as layout:
        with layout.toolbar.clear() as tb:
            tb.density = "compact"
            tb.theme = "dark"
            viewer.ui_controls(mode="trame")
            v3.VBtn(icon="mdi-palette", click=change_color)
        with layout.content:
            view = viewer.ui(add_menu=False, mode="trame")


    # Show UI
    await layout.ready
    layout


.. _sphx_glr_download_tutorial_09_trame_a_getting_started.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/09_trame/a_getting_started.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: a_getting_started.ipynb <a_getting_started.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: a_getting_started.py <a_getting_started.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: a_getting_started.zip <a_getting_started.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
