Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knitrdrawio does not work in headless environments (Docker, CI/CD, remote servers without displays, ...) #2

Closed
nergiszaim opened this issue Apr 15, 2022 · 8 comments · Fixed by #3

Comments

@nergiszaim
Copy link

nergiszaim commented Apr 15, 2022

Hi, I am running the below code in a docker environment and I am getting the error:

Any ideas?

@nergiszaim
Copy link
Author

[](url
Screen Shot 2022-04-15 at 10 08 38 AM
)

@nergiszaim
Copy link
Author

Screen Shot 2022-04-15 at 10 10 28 AM

@rchaput
Copy link
Owner

rchaput commented Apr 15, 2022

Hmm, this is weird. This means that drawio should have produced the image at test_files/figure-html/nz-diagram.svg, but knitr does not find the file. Perhaps a problem of relative path? Can you open a shell inside your Docker and see if the file exists?

Another option could be to force the engine to use a simpler path. For example:

This should create the diagram in the working directory. (or use fig.path="img/" to put the diagram in an img/ folder).
Maybe the "test_figures" folder was deleted, but I think it is unlikely to happen just after the diagram is produced but before knit prints the image.

@nergiszaim
Copy link
Author

your "For examplescript didn't populate... I triedfig.path="img/"` and it created the folder but I am getting the same error

@nergiszaim
Copy link
Author

image

@rchaput
Copy link
Owner

rchaput commented Apr 17, 2022

I am not sure why this doesn't work, the problem does not appear in a non-Docker context. Can you provide the Docker file you are using, so I can try and debug?

@rchaput
Copy link
Owner

rchaput commented Apr 17, 2022

Just a quick heads-up: I have been able to replicate this issue.

Apparently, draw.io requires a graphical server to work, which is missing in Docker and other "headless" environments. Basically, it means that it is complicated to run draw.io in a CI/CD pipeline.

As per the official repository, there seems to be 2 solutions:

  1. Run drawio through xvfb-run, which will simulate a virtual display. That means I must change the way drawio is invoked in this package. I will investigate on this, as it seems the best solution, but this will take some time, as we do not want to require xvfb in non-headless environments.

  2. Start a virtual display server by running xvfb & before rendering the document. If I understand correctly, drawio should recognize there is a virtual display available. Maybe it will require to explicitly set the display, e.g., using export DISPLAY=:1 or something like that. This can (must) be done outside the knitrdrawio package, which means this is an applicable workaround that you can use in the meantime.

@rchaput rchaput changed the title knitr::include_graphics Knitrdrawio does not work in headless environments (Docker, CI/CD, remote servers without displays, ...) Apr 17, 2022
@rchaput rchaput mentioned this issue May 2, 2022
@rchaput rchaput closed this as completed in #3 May 2, 2022
@rchaput
Copy link
Owner

rchaput commented May 2, 2022

Sorry for the delay, there were several bugs in draw.io (or most likely electron). The new version should work in Docker containers, however, it requires Draw.io 16.0.0.
More recent versions use a version of electron that has a problem with D-Bus, as acknowledged by others: rlespinasse/docker-drawio-desktop-headless#26

It is also required to install the xvfb package (through the distribution's package manager, such as apt).
I have included the instructions in the Readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants