Skip to main content

An enhanced version of ipywidgets's interactive widgets.

Project description

einteract

Binder PyPI version Downloads

An enhanced interactive widget that lets you observe any trait of widgets, observe multiple functions and build beautiful dashboards which can be turned into full screen. This is a wrapper library around interact functionality in ipyslides which also provides rich content representations.

Installation

You can install einteract using pip:

pip install einteract

Or if you prefer to install from source, clone the repository and in its top folder, run:

pip install -e .

Interactive Playground

✨ Try it in your browser ✨

Jupyter Lab Notebook Binder
Binder

Features

  • InteractBase: Create interactive dashboard applications with minimal code by extending the InteractBase class and defining methods with the @callback decorator.
  • Custom Widgets:
    • Included custom built widgets for enhanced interaction.
    • Pass any DOMWidget as a parameter to interact/interactive functions unlike default ipywidgets.interactive behavior.
    • Observe any trait of the widget by 'widget_name.trait_name' where 'widget_name' is assigned to a widget/fixed(widget) in control parameters, OR '.trait_name' if trait_name exists on instance of interactive.
    • You can use '.fullscreen' to detect fullscreen change and do actions based on that.
    • Add ipywidgets.Button to hold callbacks which use it as paramter for a click
  • Plotly Integration: Modified plotly support with additional traits like selected and clicked
  • HTML support:
    • Convert matplotlib plots to HTML format using plt2html.
    • Any (supported) python object can be converted to html using html, hstack and vstack function.
  • JupyTimer: A non-blocking widget timer for Jupyter Notebooks without threading/asyncio.
  • Event Callbacks: Easy widget event handling with the @callback decorator inside the subclass of InteractBase or multiple functions in interact/interactive functions.
  • Full Screen Mode: Transform your dashboards into full-screen applications by added button.

Usage Example

import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as ipw
import pandas as pd
import plotly.graph_objects as go
import einteract as ei

@ei.callback('out-click', throttle = 200) # limit click rate by 200 ms
def on_click(cdata,html):
    display(pd.DataFrame(cdata or {}))

def on_select(sdata, html):
    plt.scatter(sdata.get('xs',[]),sdata.get('ys',[]))
    html.value = ei.plt2html().value

def detect_fs(fig, fs):
    print("isfullscreen = ",fs)
    fig.layout.autosize = False # double trigger
    fig.layout.autosize = True

@ei.interact(
    on_select,
    on_click,
    detect_fs,
    fig = ei.patched_plotly(go.FigureWidget()), 
    html = ipw.HTML('**Select Box/Lesso on figure traces**'),
    A = (1,10), omega = (0,20), phi = (0,10),
    sdata = 'fig.selected', cdata = 'fig.clicked', fs = '.isfullscreen',
    post_init = lambda dash: (
        dash.set_css({
            '.left-sidebar':{'background':'whitesmoke'},
            ':fullscreen': {'height': '100vh'}}
        ),
        dash.set_layout(
            left_sidebar=['A','omega','phi','html','out-main'], 
            center=['fig','out-click'], 
            pane_widths=[3,7,0],
        ),
    ),
)
def plot(fig:go.FigureWidget, A, omega,phi): # adding type hint allows auto-completion inside function
    fig.data = []
    x = np.linspace(0,10,100)
    fig.add_trace(go.Scatter(x=x, y=A*np.sin(omega*x + phi), mode='lines+markers'))

einteract.gif

Comprehensive Examples

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

einteract-1.3.7.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

einteract-1.3.7-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file einteract-1.3.7.tar.gz.

File metadata

  • Download URL: einteract-1.3.7.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for einteract-1.3.7.tar.gz
Algorithm Hash digest
SHA256 3a447912abb7627d866aafab4c6d3d6ec77e849a489fb9d49f496b56c5aa1dd7
MD5 0ab154f7f7eabc31f2f5f60ab968873e
BLAKE2b-256 90b955a60756bac0862e273feb68a182f776203b6fda1809a6cd2129f252bc52

See more details on using hashes here.

File details

Details for the file einteract-1.3.7-py2.py3-none-any.whl.

File metadata

  • Download URL: einteract-1.3.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for einteract-1.3.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b5a5510ec410a457959550cdd33a3faa498c42b72129253ec077d99386964791
MD5 73ffb7ba9ee9b0dfac0ea68bb9ec7ee7
BLAKE2b-256 e48148ea3c7d3b4873ae113151a3ca3ce30426c9b8bcadf94f48a14d384b9769

See more details on using hashes here.

Supported by

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