Package: nbtools
nbtools for JupyterLabnbtoolsis a framework for creating user-friendly Jupyter notebooks that are accessible to both programming and non-programming users. It is a core component of theg2nb project. The package provides:A decorator which can transform any Python function into an interactive user interface.A toolbox interface for encapsulating and adding new computational steps to a notebook.Flexible theming and APIs to extend the nbtools functionality.Looking for classic Jupyter Notebook support?Jupyter Notebook support is available, albeit not in active development. You can find it in its own branch.Just click here!RequirementsJupyterLab >= 3.0ipywidgets >= 7.5.0DockerA Docker image with nbtools and the full JupyterLab stack is available through DockerHub.dockerpullg2nb/lab
dockerrun--rm-p8888:8888g2nb/labInstallationAt the moment you may install a prerelease version from pip or create a development install from GitHub:pipinstall--prenbtoolsOR# Install ipywidgets, if you haven't alreadyjupyternbextensionenable--pywidgetsnbextension
jupyterlabextensioninstall@jupyter-widgets/jupyterlab-manager# Clone the nbtools repositorygitclonehttps://github.com/g2nb/nbtools.gitcdnbtools# Install the nbtools JupyterLab prototypepipinstall-e.
jupyterlabextensiondevelop.--overwrite
jupyternbextensioninstall--pynbtools--symlink--sys-prefix
jupyternbextensionenable--pynbtools--sys-prefixIf installing from GitHub, before nbtools will load in your JupyterLab environment, you'll also need to build its
labextension (see Development below).DevelopmentTo develop with nbtools, you will need to first install npm or yarn, as well as install nbtools' dependencies. One way
to do this is through conda. An example is given below. Run these commands within the top-level directory of the repository.condainstallnpm.# Install npmnpminstall# Install package requirementsnpmrunbuild# Build the packagejupyterlabbuild# Build JupyterLab with the extension installedYou can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in
the extension's source and automatically rebuild the extension. To develop, run each of the following commands in a
separate terminal.jlpmrunwatch
jupyterlabThejlpmcommand is JupyterLab's pinned version ofyarnthat is installed with JupyterLab. You
may useyarnornpmin lieu ofjlpm.With the watch command running, every saved change will immediately be built locally and available in your running
JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the
extension to be rebuilt).By default, thejlpm run buildcommand generates the source maps for this extension to make it easier to debug using
the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:jupyterlabbuild--minimize=FalseUninstallpipuninstallnbtoolsGetting StartedLet's start by writing a simple Hello World function and turning it into an interactive widget. Go ahead and install nbtools, launch
Jupyter and open a new, blank notebook.Once that's completed, let's write a basic function. The function below accepts a string and prints a brief message. By default, the message addresses the world. For good measure we will also add a docstring to document the function.defsay_hello(to_whom='World'):"""Say hello to the world or whomever."""print('Hello '+to_whom)This is pretty basic Python and hopefully everything so far is familiar. Next, we will turn this function into an interactive widget with just an import statement and one line of code. Update your code to what is shown below and execute the cell.importnbtools@nbtools.build_uidefsay_hello(to_whom='World'):"""Say hello to the world or whomever."""print('Hello '+to_whom)You should now see a widget containing a web form. This form will prompt for the value of theto_whomparameter. The docstring will also appear as a description near the top of the widget. Go ahead and change theto_whomvalue, then click the "Run" button. This will execute the function and print the results below. Meanwhile, the form will also collapse, making more room on your screen.With the push of a button, you've run thesay_hellofunction!This is exciting, but it is far from the only feature of the nbtools package. You can edit markdown cells using a WYSIWYG editor, customize how your function displays, chain together multiple related functions, make widgets from existing third-party methods, create a library of interactive tools (just click the Tools button on the toolbar and you will seesay_hellohas already added itself) and more! Just see the documentation links below.FeaturesUI BuilderUI OutputTool Manager APIWYSWYG Editor