A framework for user-friendly widgets and tools in Jupyter Notebook.
Project description
nbtools
nbtools is a package for creating user-friendly Jupyter notebooks that are accessible to both programming and non-programming users. 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.
- A WYSIWYG editor for markdown cells (provided as part of the accompanying
juptyter-wyswyg
package).
nbtools was developed as part of the GenePattern Notebook environment. This environment also serves as an example of how nbtools can be extended and applied to a specific domain: in its case, bioinformatics.
Installation
nbtools is available through PIP and conda. Just run one of the following commands.
pip install nbtools
or
conda install -c genepattern nbtools
If using Jupyter Notebook version <= 5.2, you will need to execute additional commands to install and enable the nbextension. This is not necessary in Jupyter 5.3+.
jupyter nbextension install --py nbtools
jupyter nbextension enable --py nbtools
Getting Started
Let'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.
def say_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.
import nbtools
@nbtools.build_ui
def say_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 the to_whom
parameter. The docstring will also appear as a description near the top of the widget. Go ahead and change the to_whom
value, 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 the say_hello
function!
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 see say_hello
has already added itself) and more! Just see the documentation links below.
Features
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nbtools-20.9.1.tar.gz
.
File metadata
- Download URL: nbtools-20.9.1.tar.gz
- Upload date:
- Size: 61.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eeb0c76ce683600a85bc16b702a607e8879617ff16ae5fa431e062f2698bf26 |
|
MD5 | 3df94b16d67dddd0011fdfcbe559f013 |
|
BLAKE2b-256 | c6911452a908b3243fdb44de621e0d9a59756b7723de3c68be39836a307b0309 |
File details
Details for the file nbtools-20.9.1-py3-none-any.whl
.
File metadata
- Download URL: nbtools-20.9.1-py3-none-any.whl
- Upload date:
- Size: 122.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c74b92b2265faae726830db5d28a6160c5ee7fae42efaf2425eafd452f68322c |
|
MD5 | b4c8c93ac0fa1bf37623958f32cf9193 |
|
BLAKE2b-256 | a25bc3b523e89ba558e049d52517852152e9b46d1bff07e72db72469179eb5a1 |