Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nyaplot generates no plot in iruby running in jupyterhub

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?

like image 352
William Seligman Avatar asked Oct 29 '22 06:10

William Seligman


1 Answers

I don't know much about JupyterHub. But Nyaplot has not been updated for several years.

If you want to generate plot in iruby, try these projects.

  • https://github.com/ruby-numo/numo-gnuplot
  • https://github.com/zach-capalbo/iruby-plotly
  • https://github.com/SciRuby/daru-view

Following projects are experimental.

  • https://github.com/red-data-tools/charty
  • https://github.com/SciRuby/rubyplot
like image 79
kojix2 Avatar answered Nov 17 '22 20:11

kojix2