All Projects → pixiedust → Pixiedust_node

pixiedust / Pixiedust_node

Licence: apache-2.0
Jupyter magic to allow Node.js code to run in a notebook

Programming Languages

javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pixiedust node

Jupyter Radare2
Just a simple radare2 Jupyter kernel
Stars: ✭ 109 (-38.42%)
Mutual labels:  jupyter, notebook
Signals And Systems Lecture
Continuous- and Discrete-Time Signals and Systems - Theory and Computational Examples
Stars: ✭ 166 (-6.21%)
Mutual labels:  jupyter, notebook
Spark R Notebooks
R on Apache Spark (SparkR) tutorials for Big Data analysis and Machine Learning as IPython / Jupyter notebooks
Stars: ✭ 109 (-38.42%)
Mutual labels:  jupyter, notebook
Jupytemplate
Templates for jupyter notebooks
Stars: ✭ 85 (-51.98%)
Mutual labels:  jupyter, notebook
Practical Machine Learning With Python
Master the essential skills needed to recognize and solve complex real-world problems with Machine Learning and Deep Learning by leveraging the highly popular Python Machine Learning Eco-system.
Stars: ✭ 1,868 (+955.37%)
Mutual labels:  jupyter, notebook
Fastai Course 1
Docker environment for fast.ai Deep Learning Course 1 at http://course.fast.ai
Stars: ✭ 98 (-44.63%)
Mutual labels:  jupyter, notebook
Molecular Design Toolkit
Notebook-integrated tools for molecular simulation and visualization
Stars: ✭ 123 (-30.51%)
Mutual labels:  jupyter, notebook
Sparkmagic
Jupyter magics and kernels for working with remote Spark clusters
Stars: ✭ 954 (+438.98%)
Mutual labels:  jupyter, notebook
Jupyterlab Interactive Dashboard Editor
A drag-and-drop dashboard editor for JupyterLab
Stars: ✭ 165 (-6.78%)
Mutual labels:  jupyter, notebook
Fastdoc
Create publication-quality books from Jupyter notebooks
Stars: ✭ 134 (-24.29%)
Mutual labels:  jupyter, notebook
Nbconflux
nbconflux converts Jupyter Notebooks to Atlassian Confluence pages
Stars: ✭ 82 (-53.67%)
Mutual labels:  jupyter, notebook
Jupyter themes
A plugin to select syntax highlighting on Jupyter
Stars: ✭ 151 (-14.69%)
Mutual labels:  jupyter, notebook
Notebook
Jupyter Interactive Notebook
Stars: ✭ 8,710 (+4820.9%)
Mutual labels:  jupyter, notebook
Prml
PRML algorithms implemented in Python
Stars: ✭ 10,206 (+5666.1%)
Mutual labels:  jupyter, notebook
Geonotebook
A Jupyter notebook extension for geospatial visualization and analysis
Stars: ✭ 1,007 (+468.93%)
Mutual labels:  jupyter, notebook
Kubeflow
Machine Learning Toolkit for Kubernetes
Stars: ✭ 11,028 (+6130.51%)
Mutual labels:  jupyter, notebook
P5 Notebook
A minimal Jupyter Notebook UI for p5.js kernels running in the browser
Stars: ✭ 26 (-85.31%)
Mutual labels:  jupyter, notebook
Dyalog Jupyter Kernel
A Jupyter kernel for Dyalog APL
Stars: ✭ 26 (-85.31%)
Mutual labels:  jupyter, notebook
Ipyexperiments
jupyter/ipython experiment containers for GPU and general RAM re-use
Stars: ✭ 128 (-27.68%)
Mutual labels:  jupyter, notebook
Iswift
A Swift kernel for IPython.
Stars: ✭ 144 (-18.64%)
Mutual labels:  jupyter, notebook

pixiedust_node

PixieDust extension that enable a Jupyter Notebook user to invoke Node.js commands.

schematic

How it works

The pixiedust_node Python module has access to Pixiedust's display API to render charts and maps. When pixiedust_node is imported into a notebook, a Node.js sub-process is setup and the notebook is configured so that cells beginning with '%%node' may contain JavaScript code: that code is piped to the Node.js sub-process automatically. The output of the Node.js process is parsed by pixiedust_node to handle the use of functions display/print/store/html/image. The pixiedust_node module also allows npm installs to be initiated from within the notebook. This achieved with further npm sub-processes whose output appears in the notebook.

Prerequisites

To use pixiedust_node you need to be running a Jupyter notebooks with the Pixedust extension installed. Notebooks can be run locally by installing Pixiedust and its prerequisites.

You also need Node.js/npm installed. See the Node.js downloads page to find an installer for your platform.

Installation

Inside your Jupyter notebook, install pixiedust_node with

!pip install pixiedust_node

Running

Once installed, a notebook can start up pixiedust_node with:

import pixiedust_node

Using %%node

Use the %%node prefix in a notebook cell to indicate that the content that follows is JavaScript.

%%node
print(new Date());

Installing npm modules

You can install any npm module to use in your Node.js code from your notebook. To install npm modules, in a Python cell:

npm.install('silverlining')

or install multiple libraries in one go:

npm.install( ('request', 'request-promise') )

and then "require" the modules in your Node.js code.

%%node
var silverlining = require('silverlining');
var request = require('request-promise');

You may also do :

  • npm.uninstall('packagename') - to remove an npm module (or npm.remove('packagename'))
  • npm.list() - to list the installed modules

Node.js helper functions

Node.js functions are available to interact with the Notebook

  • print(x) - print out the value of variable x
  • display(x) - use Pixiedust's display function to visualise an array of data
  • store(x,'y') - turn a JavaScript array x into a Pandas data frame and store in Python variable y
  • html(x) - render HTML string x in a notebook cell
  • image(x) - render image URL x in a notebook cell
  • help() - show help

print

%%node
// connect to Cloudant using Silverlining
var url = 'https://reader.cloudant.com/cities';
var cities = silverlining(url);

// fetch number of cities per country
cities.count('country').then(print);

display

%%node

// fetch cities called York
cities.query({name: 'York'}).then(display);

store

** This function is deprecated as Node.js global variables are copied to the Python environment automatically **

%%node

// fetch the data and store in Pandas dataframe called 'x'
cities.all({limit: 2500}).then(function(data) {
  store(data, 'x');
});

The dataframe 'x' is now available to use in a Python cell:

x['population'].sum()

html

%%node
var str = 'Sales are up <b>25%</b>';
html(str);

image

%%node
var url = 'http://myserver.com/path/to/image.jpg';
image(url);

help

%%node
help();

Node.js-Python bridge

Any global variables that you create in your %%node cells will be automatically copied to equivalent variables in Python. e.g if you create some variables in a Node.js cell:

%%node
var str = "hello world";
var n1 = 4.1515;
var n2 = 42;
var tf = true;
var obj = { name:"Frank", age: 42 };
var array_of_strings = ["hello", "world"];
var array_of_objects = [{a:1,b:2}, {a:3, b:4}];

Then these variables can be used in Python:

# Python cell
print str, n1, n2, tf
print obj
print array_of_strings
print array_of_objects

Strings, numbers, booleans and arrays of such are converted to their equivalent in Python. Objects are converted into Python dictionaries and arrays of objects are automatically converted into a Pandas DataFrames.

Note that only variables declared with var are moved to Python, not constants declared with const.

If you want to move data from an asynchronous Node.js callback, remember to write it to a global variable:

%%node
var googlehomepage = '';
request.get('http://www.google.com').then(function(data) {
  googlehomepage = data;
  print('Fetched Google homepage');
});

Similarly, Python variables of type str, int, float, bool, unicode, dict or list will be moved to Node.js when a cell is executed:

# Python cell
a = 'hello'
b = 2
b = 3
c= False
d = {}
d["x"] = 1
d["y"] = 2
e = 3.142

The variables can then be used in Node.js:

%%node
console.log(a,b,c,d,e);
// hello 3 false { y: 2, x: 1 } 3.142

Managing the Node.js process

If enter some invalid syntax into a %%node cell, such as code with more opening brackets than closing brackes, then the Node.js interpreter may not think you have finished typing and you receive no output.

You can cancel execution by running the following command in a Python cell:

node.cancel()

If you need to clear your Node.js variables and restart from the beginning then issue the following command in an Python cell:

node.clear()

Help

You can view the help in a Python cell:

node.help()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].