Giter VIP home page Giter VIP logo

nbinteract's Introduction

nbinteract

Read the Docs PyPI npm

nbinteract is a Python package that creates interactive webpages from Jupyter notebooks. nbinteract has built-in support for interactive plotting. These interactions are driven by data, not callbacks, allowing authors to focus on the logic of their programs.

nbinteract is most useful for:

  • Data scientists that want to create simple interactive blog posts without having to know / work with Javascript.
  • Instructors that want to include interactive examples in their textbooks.
  • Students that want to publish data analysis that contains interactive demos.

Currently, nbinteract is in an alpha stage because of its quickly-changing API.

Examples

Most plotting functions from other libraries (e.g. matplotlib) take data as input. nbinteract's plotting functions take functions as input.

import numpy as np
import nbinteract as nbi

def normal(mean, sd):
    '''Returns 1000 points drawn at random fron N(mean, sd)'''
    return np.random.normal(mean, sd, 1000)

# Pass in the `normal` function and let user change mean and sd.
# Whenever the user interacts with the sliders, the `normal` function
# is called and the returned data are plotted.
nbi.hist(normal, mean=(0, 10), sd=(0, 2.0), options=options)

example1

Simulations are easy to create using nbinteract. In this simulation, we roll a die and plot the running average of the rolls. We can see that with more rolls, the average gets closer to the expected value: 3.5.

rolls = np.random.choice([1, 2, 3, 4, 5, 6], size=300)
averages = np.cumsum(rolls) / np.arange(1, 301)

def x_vals(num_rolls):
    return range(num_rolls)

# The function to generate y-values gets called with the
# x-values as its first argument.
def y_vals(xs):
    return averages[:len(xs)]

nbi.line(x_vals, y_vals, num_rolls=(1, 300))

example2

Publishing

From a notebook cell:

# Run in a notebook cell to convert the notebook into a
# publishable HTML page
nbi.publish('landing_page.ipynb')

From the command line:

# Run on the command line to convert the notebook into a
# publishable HTML page.
nbinteract landing_page.ipynb

For more information on publishing, see the tutorial which has a complete walkthrough on publishing a notebook to the web.

Installation

Using pip:

pip install nbinteract

# The next two lines can be skipped for notebook version 5.3 and above
jupyter nbextension enable --py --sys-prefix widgetsnbextension
jupyter nbextension enable --py --sys-prefix bqplot

You may now import the nbinteract package in Python code and use the nbinteract CLI command to convert notebooks to HTML pages.

Tutorial and Documentation

Here's a link to the tutorial and docs for this project.

Developer Install

If you are interested in developing this project locally, run the following:

git clone https://github.com/SamLau95/nbinteract
cd nbinteract

# Installs the nbconvert exporter
pip install -e .

# To export a notebook to interactive HTML format:
jupyter nbconvert --to interact notebooks/Test.ipynb

pip install -U ipywidgets
jupyter nbextension enable --py --sys-prefix widgetsnbextension

brew install yarn
yarn install

# Start notebook and webpack servers
make -j2 serve

Contributors

nbinteract is originally developed by Sam Lau and Caleb Siu as part of a Masters project at UC Berkeley. The code lives under a BSD 3 license and we welcome contributions and pull requests from the community.

nbinteract's People

Contributors

cleb11 avatar samlau95 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.