Skip to content
Integrate Rails and Jupyter
Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
bin
doc add images Mar 5, 2019
lib
.gitignore fix Feb 2, 2019
CHANGELOG.md
Gemfile init Jan 23, 2019
README.md
Rakefile
jupyter_on_rails.gemspec
the_screenshot.png update README Jan 23, 2019

README.md

JupyterOnRails

Integrate Rails and Jupyter

Alt text

Motivation

Although it was already possible to run jupyter + iruby and require app_full_path to load Rails application context, it is a bit tiring to each time copy all the require statements.

Moreover, since Rails Way works in keeping (generally) everything under the project directory, managing the jupyter configuration installed in user global area (the iruby kernel register thing) is again a bit awkward.

With this gem, these awkwardness is to solved by following instruments:

  • rake jupyter:notebook Railtie command which invokes jupyter at your project root, and
  • The rails kernel dynamically defined by the rake task which automatically loads your Rails application.

Prerequisites

  • iruby's prerequisites must be met.

  • jupyter command must be somehow available.

    • Either
      • jupyter command (pip global install, anaconda, etc), or
      • pipenv run jupyter command (managed by Pipfile at project root)

Installation

Add these lines to your application's Gemfile:

gem 'jupyter_on_rails'

# For sessions pick either:
gem 'ffi-rzmq'
# Or
gem 'cztop'

And then execute:

$ bundle install

Usage

Starting the jupyter server is available as a rake command.

Just execute:

rake jupyter:notebook

Eventually, you'll have jupyter opened, and the kernel being available.

ApplicationRecord#to_df

User.to_df # => Daru::DataFrame is returned

Daru::DataFrame#write_model

For each row, call to_h and pass it to model.new. And then, imports them using model.insert_all on Rails >= 6, or model.import (requires adding activerecord-import to your Gemfile).

df.write_model(User)

Development

This is a railtie gem, so you'd probably want to do something like:

gem 'jupyter_on_rails', git: 'GIT_URL_OF_YOUR_REPO',
                        branch: 'the-work-branch'

or

gem `jupyter_on_rails`, path: 'jupyter_on_rails_as_sub_project'

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Yuki-Inoue/jupyter_on_rails.

You can’t perform that action at this time.