is.headless.env | R Documentation |
This functions detects whether the code runs in a "headless" environment, i.e., with no graphical server available.
is.headless.env()
The draw.io application requires a graphical server to work, this is a known limitation. However, headless environments such as Docker containers, CI/CD pipelines, remote server (through SSH), etc., do not have a display.
It is thus important to be able to detect such environments, in order to use workarounds that prevent draw.io from crashing.
We use 2 methods:
If the xrandr
tool is available, we use it to query the
configuration of the current display. If xrandr
does not find any
display, we assume to be in a headless environment.
Otherwise, we resort to a simpler test: on Linux, the $DISPLAY
environment variable controls the display server which should be used.
If it is empty, or not set, we assume to be in a headless environment.
In both methods, it is possible that the system has an available
display, which is simply not recognized at the time, e.g., because of an
incorrect configuration. This is especially the case if $DISPLAY
is
set to ""
. In this case, this functions will incorrectly believe to
be in a headless environment. Users should make sure that their system is
properly configured to avoid this.
These 2 proposed ways do not cover Windows nor Mac OS X. On such systems, the headless detection will certainly fail. By default, we consider we are not in a headless environment: the knitrdrawio engine will thus invoke draw.io normally. Maybe, by chance, it will work. The worst possible outcome is that draw.io crashes, and the document rendering will fail as well.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.