Skip to main content

Extended widgets for jupyter notebooks.

Project description

ipyumbrella

Improved ipywidgets for collections.

import ipyumbrella as uw
import matplotlib.pyplot as plt

for i in uw.Carousel().D.items(range(5), title=str):
    plt.plot(range(10 + i))

Making widgets in Jupyter is super helpful and it unlocks a lot of potential. But I often find that they can be really cumbersome to work with and I'm constantly writing wrapper functions to capture output, add them to tabs, and set the title (using the child index..... ugh).

This wraps much of that functionality up so that you can wrap a for loop without thinking and each iteration will output to a new tab, parsing the title from the iterable elements. WOW!

Install

pip install ipyumbrella

Usage

import ipyumbrella as uw
import matplotlib.pyplot as plt

Widgets

  • Carousel: sideways scrolling items of (default) width of 60%.
  • Tabs: same as ipywidgets
  • Accordion: same as ipywidgets

All of the described methods work for all widgets here. So you can interchange any of the widgets in the example.

Easily display while chaining

I come from Javascript so I've grown quite acustom to chaining. This is useful for example when wrapping an inline iterable. It means you can display a whole set of tabs without saving anything to a variable needlessly and without the extra line.

# all equivalent
carousel = uw.Carousel().display()

carousel = uw.Carousel().D

carousel = uw.Carousel()
display(carousel)

carousel = uw.Carousel()
carousel # last line in cell

Iterable (.items())

Create a right scrolling carousel of items. Useful when you're plotting like 20 graphs and doing them one on top of the other makes navigating the notebook insufferable.

for i in uw.Carousel().D.items(range(5)):
    plt.plot(range(10 + i))

You can set the tab title using a function that takes the iterable as the first argument.

for i in uw.Tabs().D.items(range(5), title='this is tab {}'.format):
    plt.plot(range(10 + i))
for i in uw.Accordion().D.items(range(5), title='see: {}'.format):
    plt.plot(range(10 + i))

Function capturing (@.function)

This gives you a bit more flexibility than wrapping an iterable. Anything from this function will be added to it's own tab.

@uw.Tabs().D.function(title='plotting {}'.format)
def tabfunc(i, j=100):
    plt.plot(range(10 + i, j))

tabfunc(5)
tabfunc(6, j=40)

Context Manager (with .item():)

This is the underlying mechanics for the other functions. What it does is, makes a new tab and append a ipywidgets.Output widget. It then uses the output widget to capture all output, like prints and plt.show() so it can display it in a tab.

carousel = uw.Carousel().D
for i in range(5):
    with carousel.item():
        plt.plot(range(10 + i))
acc = uw.Accordion().D
for i in range(5):
    with acc.item(title='Item {}'.format(i)):
        plt.plot(range(10 + i))

Internally, it's doing this.

# manually add an output as a tab above
with tabs.append(uw.Output()):
    plt.plot(range(10 + i))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipyumbrella-0.0.25.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file ipyumbrella-0.0.25.tar.gz.

File metadata

  • Download URL: ipyumbrella-0.0.25.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for ipyumbrella-0.0.25.tar.gz
Algorithm Hash digest
SHA256 127e37f7d1eb424885262fdf37890c22d32dba4d72f5c2ca78964c0959800737
MD5 4f70e7c4c700f8686362f7731ddd7db9
BLAKE2b-256 f6ff0a1e6fad876032c12f89d560dd7142e7695fad474dd4e754ce79857b2361

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page