Package: j1-nbinteract
j1-nbinteractThe Python packagej1-nbinteractis based onnbinteractv0.2.6but
implements upgraded/modified Python packages for pip inrequirements.txt:# Python `pip` dependencies for j1-nbinteract
# ------------------------------------------------------------------------------

# Unchanged modules/ranges
#
ipython>=6, <8
ipywidgets>=7.5.0, <8
toolz>=0.8, <1
docopt>=0.6.2, <1
numpy>=1, <2

# More recent versions required by e.g. nbclient
#
# nbformat>=4.4.0, <5, traitlets>=4.3, <5
nbformat>=5.0
traitlets>=5.0

# Recent version of `bqplot` for Jupyter `Notebook v7` (JupyterLab)
# NOTE: currently NOT supported for j1-nbinteract v1.x
#
# bqplot>=0.12

# Pinned version of `bqplot` for Jupyter `Notebook v6` (Classic Notebook)
#
bqplot==0.11.9

# Upgraded/Pinned to `Jinja2` latest that support func `contextfilter`
#
jinja2==3.0

# Set new range for `nbconvert`
#
nbconvert>=5.6, <7

# Pinned `markupsafe` latest that support func `soft_unicode`
#
markupsafe==2.0.1NOTE: The functionality ofj1-nbinteractis thesameas provided by the original packagenbinteractof version 0.2.6.CLIFor compatibility reasons, the (Python) module build-inCLIhas the samenamenbinteractas used in the original package (nbinteract v0.2.6).NOTE: The original CLInbinteractof version 0.2.6cannotbe used
for J1 webpages.Javascript Core moduleThe Javascript Core modulej1-nbinteract-coreis heavily modified for the
use with J1-Template.NOTE: The original JS core modulenbinteract-coreof version 0.2.6cannotbe used for J1 webpages.nbinteract v0.2.6nbinteractis a Python package that creates interactive webpages from Jupyter
notebooks.nbinteractalso 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.nbinteractis 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,nbinteractis in an alpha stage because of its quickly-changing
API.ExamplesMost plotting functions from other libraries (e.g.matplotlib) take data as
input.nbinteract's plotting functions take functions as input.importnumpyasnpimportnbinteractasnbidefnormal(mean,sd):'''Returns 1000 points drawn at random fron N(mean, sd)'''returnnp.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)Simulations are easy to create usingnbinteract. 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)defx_vals(num_rolls):returnrange(num_rolls)# The function to generate y-values gets called with the# x-values as its first argument.defy_vals(xs):returnaverages[:len(xs)]nbi.line(x_vals,y_vals,num_rolls=(1,300))PublishingFrom a notebook cell:# Run in a notebook cell to convert the notebook into a publishable HTML page:## nbi.publish('my_binder_spec', 'my_notebook.ipynb')## Replace my_binder_spec with a Binder spec in the format# {username}/{repo}/{branch} (e.g. SamLau95/nbinteract-image/master).## Replace my_notebook.ipynb with the name of the notebook file to convert.## Example:nbi.publish('SamLau95/nbinteract-image/master','homepage.ipynb')From the command line:# Run on the command line to convert the notebook into a publishable HTML page.## nbinteract my_binder_spec my_notebook.ipynb## Replace my_binder_spec with a Binder spec in the format# {username}/{repo}/{branch} (e.g. SamLau95/nbinteract-image/master).## Replace my_notebook.ipynb with the name of the notebook file to convert.## Example:nbinteractSamLau95/nbinteract-image/masterhomepage.ipynbFor more information on publishing, see thetutorialwhich has a complete
walkthrough on publishing a notebook to the web.InstallationUsingpip:pipinstallnbinteract# The next two lines can be skipped for notebook version 5.3 and abovejupyternbextensionenable--py--sys-prefixwidgetsnbextension
jupyternbextensionenable--py--sys-prefixbqplotYou may now import thenbinteractpackage in Python code and use thenbinteractCLI command to convert notebooks to HTML pages.Tutorial and DocumentationHere's a link to the tutorial and docs for this project.Developer InstallIf 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 serveFeedbackIf you have any questions or comments, send us a message on theGitter channel. We appreciate your feedback!Contributorsnbinteractis originally developed bySam Lauand 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.