MATLAB: Polar plots(polarplot) and display volume(volshow) functions don’t work on Linux MATLAB Web App Server

I have ploar plot (e.g. polarplot) functions and/or volshow function in my app. The app works fine with MATLAB desktop. But after I deployed it to a Linux based MATLAB Web App Server, these functions don't work. 
For example, for polarplot function, I see error messages like below
2021-02-12 15:41:10 MATLAB has experienced a low-level graphics error, and may not have drawn correctly.
2021-02-12 15:41:10 Read about what you can do to prevent this issue by running this command: opengl problems,
2021-02-12 15:41:10 then restart MATLAB.
2021-02-12 15:41:41 Couldn't create JOGL canvas--using painters
For volshow function, I see
2021-02-12 15:42:52 Warning: Cannot set Renderer to OpenGL on this figure.
2021-02-12 15:42:52 Warning: An error occurred while drawing the scene: Cookie 72057594037927941 does not refer to a node in the scene tree
2021-02-12 15:42:52 > In defaulterrorcallback (line 12)
2021-02-12 15:42:52 In waitforallfiguresclosed (line 16)
2021-02-12 15:44:06 MATLAB has experienced a low-level graphics error, and may not have drawn correctly.
2021-02-12 15:44:06 Read about what you can do to prevent this issue by running this command: opengl problems,
2021-02-12 15:44:06 then restart MATLAB.

Best Answer

These functions need Server Side Rendering (SSR) to work with MATLAB Web App Server.
If you need applications that require server side rendering, you will need to configure your Linux system with a full desktop.  If you are running on a system with a full desktop you will also have to do two things below:
1. Set DISPLAY environment variable
You will need to configure the webapps launcher process to launch workers with the DISPLAY environment variable correctly set.  For this, you will have to direct systemd to interpret a set-up file.  First, enter the following systemctl command
Edit command
sudo systemctl edit mw-webapps-launcher-<version like R2021a>.service
This will bring you up in emacs.  Now, enter the following into the editor:
conf file contents
[Service]Environment="DISPLAY=:0"
2. Direct X-windows service to allow connection
You will also have to direct the X-windows service to allow connection from the webapps launcher service.
As a quick test try:
xhost command
sudo xhost +SI:localuser:MwWebAppsWorker<version list R2021a>
However, to persist the change across reboots, use sudo to edit /etc/profile adding:
edit /etc/profile
if [ "$DISPLAY" != "" ]; then   xhost +SI:localuser:MwWebAppsWorker<version lie R2021a>fi