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

Support calling orca through xvfb on Linux #1523

Merged
merged 5 commits into from
May 25, 2019
Merged

Support calling orca through xvfb on Linux #1523

merged 5 commits into from
May 25, 2019

Conversation

jonmmease
Copy link
Contributor

@jonmmease jonmmease commented Apr 15, 2019

Overview

This PR adds support for calling orca through Xvfb, simplifying the process of using plotly.py's image export functions in a headless Linux environment.

This is accomplished through the addition of a new use_xvfb parameter in plotly.io.orca.config. This parameter may be set to False, True, or 'auto', where:

  • False: Never use xvfb
  • True: Use Xvfb and raise an error if xvfb-run is not found on the system Path
  • 'auto': Use Xvfb if running on Linux, no display serer is detected (determined by checking the DISPLAY environment variable), and xvfb-run is on the path.

use_xvfb will default to False for the remainder of version 3, but it will default to 'auto' in version 4. The new orca_defaults future flag may be used to enable this default behavior now.

Usage

To perform headless static image export on Linux, first install orca following the instructions at https://github.com/plotly/orca#installation. Then install Xvfb using the package manager for your Linux distribution. Then configure plotly.py to call orca through Xvfb using:

import plotly.io as pio
pio.orca.config.use_xvfb = True

Then export images as usual with:

pio.write_image(fig, 'filename.png')

Additional Changes

Add LD_PRELOAD to the list of environment variables to be excluded to be unset when calling orca to avoid breaking orca in Colab (See https://medium.com/@n0mad/how-i-trained-starcraft-2-ais-using-googles-free-gpus-44bc635b0418 for discussion of the Colab's use of tcmalloc).

@jonmmease
Copy link
Contributor Author

jonmmease commented Apr 15, 2019

Using plotly.py with orca in Colab

!pip install https://11956-14579099-gh.circle-artifacts.com/0/dist/plotly-3.8.0%2B2.g4a2ccc2e.tar.gz

!wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage -O /usr/local/bin/orca
!chmod +x /usr/local/bin/orca
!apt-get install xvfb libgtk2.0-0 libgconf-2-4
from _plotly_future_ import v4
import plotly.io as pio
import plotly.graph_objs as go

fig = go.Figure(data=[{'y': [3, 2, 4]}])
pio.to_image(fig)

@jonmmease
Copy link
Contributor Author

orca setup for use in Kaggle kernels

!pip install https://11970-14579099-gh.circle-artifacts.com/0/dist/plotly-3.8.0%2B3.g27437f41.tar.gz
!conda install -y -c plotly plotly-orca
!apt-get -y install libxss1

If the Kaggle Python docker image (https://github.com/Kaggle/docker-python/blob/master/Dockerfile) was updated to include conda install -y -c plotly plotly-orca and apt-get -y install libxss1 then orca would work out-of-the-box with the changes in this branch since Xvfb is already included.

@jonmmease
Copy link
Contributor Author

Unfortunately, it appears this approach won't work with Azure notebooks because sudo is required to use apt-get to install Xvfb and sudo isn't supported right now https://github.com/Microsoft/AzureNotebooks/issues/303.

be used to run orca.  May by True, False, or 'auto'.

The default will be False until v4 (or when the orca_defaults future
flag is enabled).  In v4 the default will change to 'auto', in which
case xvfb-run is used automatically if plotly.py is running on a Linux
machine without a display server with xvfb-run available.
# Conflicts:
#	_plotly_future_/v4.py
@jonmmease jonmmease changed the title WIP: Auto-detect Xvfb on Linux if no X11 server found Support calling orca through xvfb on Linux May 25, 2019
@jonmmease jonmmease added this to the v3.10 milestone May 25, 2019
@jonmmease jonmmease merged commit 3f890a5 into master May 25, 2019
@nicolaskruchten nicolaskruchten deleted the enh_orca_xvfb branch June 19, 2020 16:13
@atan4583
Copy link

atan4583 commented Jun 24, 2020

Hi @jonmmease

I installed orca using conda install -c plotly plotly-orca on AWS Linux server, but got this error when calling plotly:

/opt/conda/envs/pysig/lib/orca_app/orca: error while loading shared libraries: libgdk_pixbuf-2.0.so.0: cannot open shared object file: No such file or directory

According to this, I need to install libgtk2.0-0 and libgconf-2-4, but AWS AMI has its own Linux distribution which does not have the 2 packages. Though I also installed Xvfb on AWS AMI, it won't fix the orca error without the 2 missing packages.

So I tried the standalone orca binary route and downloaded orca-1.3.1.AppImage, made it executable and created a symbolic link named orca to point to the orca-1.3.1.AppImage. But when I tried orca --help , I got the following error

fuse: failed to exec fusermount: No such file or directory

Cannot mount AppImage, please check your FUSE setup.
You might still be able to extract the contents of this AppImage
if you run it with the --appimage-extract option.
See https://github.com/AppImage/AppImageKit/wiki/FUSE
for more information
open dir error: No such file or directory

I am not sure how to install FUSE on AWS linux, thus settled on trying AppImage with the --appimage-extract flag.

Followed the --appimage-extract flag example in your post , I installed Xvfb on AWS AMI san libgtk2.0-0 and libgconf-2-4 packages as they are not available on AWS linux AMI.

I then tried /opt/conda/envs/pysig/bin/orca-1.3.1.AppImage --appimage-extract. After the contents got extracted to /home/ec2-user/squashfs-root folder, I ran:

xvfb-run --auto-servernum --server-args "-screen 0 1280x800x24" /home/ec2-user/squashfs-root/orca "$@" > /opt/conda/envs/pysig/bin/orca
chmod 777 /opt/conda/envs/pysig/bin/orca

But orca --help returned this:

/opt/conda/envs/pysig/bin/orca: line 1: /home/ec2-user/squashfs-root/orca:: No such file or directory

I also tried orca-1.2.1-x86_64.AppImage in place of orca-1.3.1.AppImage to no avail. Does the glitch to do with not having libgtk2.0-0 and libgconf-2-4?

orca seems like a big hassle, cant find any help and use case examples beyond windows & ubuntu platform. No help on here nor stackoverflow nor plotly community.

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 this pull request may close these issues.

2 participants