5

I'm trying to set up a Ruby kernel within an existing multi-user jupyterhub installation. It works in all of my tests, except that plots created by nyaplot (the only plotting package I could find that works within iruby) don't show up in the notebook. For example, the following code (from one of the Nyaplot tutorials) gives no error (not even in the syslog file) but no plot:

require 'nyaplot'
plot = Nyaplot::Plot.new
sc = plot.add(:scatter, [0,1,2,3,4], [-1,2,-3,4,-5])
color = Nyaplot::Colors.qual
sc.color(color)
plot.show # show plot on IRuby notebook

Background:

Here's how I set up iruby to run in jupyterhub. I'm giving the entire process so (a) you can spot if anything is missing, and (b) so you know that if you say something like "add [this] to the Gemfile" you're going to have to tell me where to put the Gemfile, since jupyterhub is not running iruby out of a particular directory.

The OS is CentOS 7.3. Since its default version of ruby is too old to run iruby, I installed a version of ruby using ruby-install:

wget -O ruby-install-0.6.1.tar.gz https://github.com/postmodern/ruby-install/archive/v0.6.1.tar.gz
tar -xzvf ruby-install-0.6.1.tar.gz 
cd ruby-install-0.6.1
make
make install
ruby-install ruby 2.3.4

(I used ruby 2.3, instead of 2.4, because it turned out that at least one component of sciruby-full doesn't work with 2.4 yet.) After the installation, a message says that ruby is installed in /opt/rubies/ruby-2.3.4.

Next come the package installations.

I had to make sure that nothing was installed in my home directory, because in a multi-user system the other users don't have access to my home directory's files. I'm listing below all the packages I eventually installed to try to solve this problem:

export RUBYDIR=/opt/rubies/ruby-2.3.4
export PATH=${RUBYDIR}/bin:$PATH
export LD_LIBRARY_PATH=${RUBYDIR}/lib:$LD_LIBRARY_PATH
export GEM_HOME=${RUBYDIR}
export GEM_PATH=${RUBYDIR}
gem install --no-user-install cztop rbczmq iruby
gem install --no-user-install pry pry-doc awesome_print gnuplot rubyvis nyaplot
gem install --no-user-install sciruby-full
gem install --no-user-install zeromq ffi-rzmq gnuplotrb

Next comes installing the iruby kernel into jupyterhub.

After looking at the results of "iruby register --force",
I created the file /usr/local/share/jupyter/kernels/ruby:

{"argv":[
         "/usr/local/bin/jupyter-ruby-env.sh",
         "{connection_file}"
          ],
 "display_name":"Ruby",
 "language":"ruby"
}

In /usr/local/bin/jupyter-ruby-env.sh:

#!/usr/bin/bash -l                                                                                                                                    
export RUBYDIR=/opt/rubies/ruby-2.3.4
export PATH=${RUBYDIR}/bin:$PATH
export LD_LIBRARY_PATH=${RUBYDIR}/lib:$LD_LIBRARY_PATH
export GEM_HOME=${RUBYDIR}
export GEM_PATH=${RUBYDIR}
exec ${RUBYDIR}/bin/iruby kernel $@

As I said, all of this works as far as basic ruby is concerned: I can run code I found in the Ruby tutorials. The only thing I don't get are plots. All of the other jupyterhub kernels I've installed (e.g., python, SageMath, Julia) have no problems plotting.

Any ideas?

4

1 回答 1

2

我对 JupyterHub 了解不多。但是 Nyaplot 已经好几年没有更新了。

如果您想在 iruby 中生成绘图,请尝试这些项目。

以下项目是实验性的。

于 2019-09-13T15:18:08.300 回答