How to fix segfaulting error with pyvista version 0.34.1

I am a newbie to dolfinx and ran into an error with pyvista.
I pull the dolfinx/lab image and create a container. Note that
ipyvtklink has been installed. In testing pyvista

from pyvista import examples
mesh = examples.download_st_helens()
warped = mesh.warp_by_scalar(‘Elevation’)
surf = warped.extract_surface().triangulate()
surf = surf.decimate_pro(0.75) # reduce the density of the mesh by 75%
surf.plot(cmap=‘gist_earth’)

Getting the following error.

/usr/local/lib/python3.9/dist-packages/pyvista/plotting/plotting.py:115: UserWarning:
This system does not appear to be running an xserver.
PyVista will likely segfault when rendering.

Try starting a virtual frame buffer with xvfb, or using
pyvista.start_xvfb()

warnings.warn(
/usr/local/lib/python3.9/dist-packages/pyvista/jupyter/notebook.py:60: UserWarning: Failed to use notebook backend:

Please install ipyvtklink to use this feature: GitHub - Kitware/ipyvtklink: 🔗 minimalist ipywidget to interface with any Python vtkRenderWindow

Falling back to a static output.
warnings.warn(
ERROR:root:bad X server connection. DISPLAY=
2022-04-24 22:11:04.402 ( 40.906s) [ E6510C00]vtkXOpenGLRenderWindow.:464 ERR| vtkXOpenGLRenderWindow (0x559e810): bad X server connection. DISPLAY=

The reason for this segfault is that you can’t run gui applications by default inside a docker container. This is what is meant by

This provides a detailed description of how one might go about enabling gui applications to be run inside a docker container.

If you happen to use Ubuntu (it may also work for some other linux operating systems), following this post allowed me to use PyVista from within a docker container, without using JupyerLab. Note: I use Ubuntu 20.04.

Alternatively, you can use PyVista from within a docker container through JupyterLab, see here . I haven’t actually tried this myself but should work well.

If you are running (like me) the container in VS Code or something that is not jupyter lab, try this, that worked for my case:
https://fenicsproject.discourse.group/t/cannot-display-pyvista-plot-in-docker-container/8202/9