einteract


Nameeinteract JSON
Version 1.3.5 PyPI version JSON
download
home_pagehttps://github.com/asaboor-gh/einteract
SummaryAn enhanced version of ipywidgets's interactive widgets.
upload_time2025-07-20 18:05:12
maintainerNone
docs_urlNone
authorAbdul Saboor
requires_python>=3.9
licenseMIT
keywords jupyter widgets ipython interact interactive
VCS
bugtrack_url
requirements ipyslides numpy pandas matplotlib
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# einteract

[![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/notebooks/index.html?path=einteract.ipynb)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/asaboor-gh/einteract/HEAD?urlpath=%2Fdoc%2Ftree%2Feinteract-demo.ipynb)
[![PyPI version](https://badge.fury.io/py/einteract.svg)](https://badge.fury.io/py/einteract)
[![Downloads](https://pepy.tech/badge/einteract)](https://pepy.tech/project/einteract)

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](https://github.com/asaboor-gh/ipyslides) which also provides rich content representations. 

![](interact.png)

## Installation

You can install einteract using pip:

```bash
pip install einteract
```

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

```bash
pip install -e .
```

## Interactive Playground
**✨ Try it in your browser ✨**
| Jupyter Lab  | Notebook | Binder |
|----|---|--- |
|  [![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/lab/index.html?path=einteract.ipynb)  |  [![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/notebooks/index.html?path=einteract.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/asaboor-gh/einteract/HEAD?urlpath=%2Fdoc%2Ftree%2Feinteract-demo.ipynb) |

## 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

```python
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',
    app_layout={'left_sidebar':['A','omega','phi','html','out-main'], 'center': ['fig','out-click'],'pane_widths':[3,7,0]},
    grid_css={'.left-sidebar':{'background':'whitesmoke'},':fullscreen': {'height': '100vh'}}, 
    )
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](einteract.gif)

## Comprehensive Examples
- Check out the [einteract-demo.ipynb](einteract-demo.ipynb) which demonstates subclassing `InteractBase`, using custom widgets, and observing multiple functions through the `@callback` decorator.
- See [Bandstructure Visualizer](https://github.com/asaboor-gh/ipyvasp/blob/d181ba9a1789368c5d8bc1460be849c34dcbe341/ipyvasp/widgets.py#L642) and [KPath Builder](https://github.com/asaboor-gh/ipyvasp/blob/d181ba9a1789368c5d8bc1460be849c34dcbe341/ipyvasp/widgets.py#L935) as comprehensive dashboards.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/asaboor-gh/einteract",
    "name": "einteract",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "Jupyter, Widgets, IPython, interact, interactive",
    "author": "Abdul Saboor",
    "author_email": "asaboor.my@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/72/6e/c5848b4df90bd8994d9f25dbc2bdca9c5dcaf4e0ce5d54462f311b291b13/einteract-1.3.5.tar.gz",
    "platform": null,
    "description": "\r\n# einteract\r\n\r\n[![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/notebooks/index.html?path=einteract.ipynb)\r\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/asaboor-gh/einteract/HEAD?urlpath=%2Fdoc%2Ftree%2Feinteract-demo.ipynb)\r\n[![PyPI version](https://badge.fury.io/py/einteract.svg)](https://badge.fury.io/py/einteract)\r\n[![Downloads](https://pepy.tech/badge/einteract)](https://pepy.tech/project/einteract)\r\n\r\nAn 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](https://github.com/asaboor-gh/ipyslides) which also provides rich content representations. \r\n\r\n![](interact.png)\r\n\r\n## Installation\r\n\r\nYou can install einteract using pip:\r\n\r\n```bash\r\npip install einteract\r\n```\r\n\r\nOr if you prefer to install from source, clone the repository and in its top folder, run:\r\n\r\n```bash\r\npip install -e .\r\n```\r\n\r\n## Interactive Playground\r\n**\u2728 Try it in your browser \u2728**\r\n| Jupyter Lab  | Notebook | Binder |\r\n|----|---|--- |\r\n|  [![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/lab/index.html?path=einteract.ipynb)  |  [![](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://asaboor-gh.github.io/einteract-docs/notebooks/index.html?path=einteract.ipynb) | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/asaboor-gh/einteract/HEAD?urlpath=%2Fdoc%2Ftree%2Feinteract-demo.ipynb) |\r\n\r\n## Features\r\n\r\n- **InteractBase**: Create interactive dashboard applications with minimal code by extending the `InteractBase` class and defining methods with the `@callback` decorator.\r\n- **Custom Widgets**: \r\n    - Included custom built widgets for enhanced interaction. \r\n    - Pass any DOMWidget as a parameter to `interact/interactive` functions unlike default `ipywidgets.interactive` behavior.\r\n    - 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.\r\n    - You can use '.fullscreen' to detect fullscreen change and do actions based on that.\r\n    - Add `ipywidgets.Button` to hold callbacks which use it as paramter for a click\r\n- **Plotly Integration**: Modified plotly support with additional traits like `selected` and `clicked`\r\n- **HTML support**: \r\n    - Convert matplotlib plots to HTML format using `plt2html`.\r\n    - Any (supported) python object can be converted to html using `html`, `hstack` and `vstack` function.\r\n- **JupyTimer**: A non-blocking widget timer for Jupyter Notebooks without threading/asyncio.\r\n- **Event Callbacks**: Easy widget event handling with the `@callback` decorator inside the subclass of `InteractBase` or multiple functions in `interact/interactive` functions.\r\n- **Full Screen Mode**: Transform your dashboards into full-screen applications by added button.\r\n\r\n## Usage Example\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport ipywidgets as ipw\r\nimport pandas as pd\r\nimport plotly.graph_objects as go\r\nimport einteract as ei\r\n\r\n@ei.callback('out-click', throttle = 200) # limit click rate by 200 ms\r\ndef on_click(cdata,html):\r\n    display(pd.DataFrame(cdata or {}))\r\n\r\ndef on_select(sdata, html):\r\n    plt.scatter(sdata.get('xs',[]),sdata.get('ys',[]))\r\n    html.value = ei.plt2html().value\r\n\r\ndef detect_fs(fig, fs):\r\n    print(\"isfullscreen = \",fs)\r\n    fig.layout.autosize = False # double trigger\r\n    fig.layout.autosize = True\r\n\r\n@ei.interact(\r\n    on_select,\r\n    on_click,\r\n    detect_fs,\r\n    fig = ei.patched_plotly(go.FigureWidget()), \r\n    html = ipw.HTML('**Select Box/Lesso on figure traces**'),\r\n    A = (1,10), omega = (0,20), phi = (0,10),\r\n    sdata = 'fig.selected', cdata = 'fig.clicked', fs = '.isfullscreen',\r\n    app_layout={'left_sidebar':['A','omega','phi','html','out-main'], 'center': ['fig','out-click'],'pane_widths':[3,7,0]},\r\n    grid_css={'.left-sidebar':{'background':'whitesmoke'},':fullscreen': {'height': '100vh'}}, \r\n    )\r\ndef plot(fig:go.FigureWidget, A, omega,phi): # adding type hint allows auto-completion inside function\r\n    fig.data = []\r\n    x = np.linspace(0,10,100)\r\n    fig.add_trace(go.Scatter(x=x, y=A*np.sin(omega*x + phi), mode='lines+markers'))\r\n\r\n```\r\n![einteract.gif](einteract.gif)\r\n\r\n## Comprehensive Examples\r\n- Check out the [einteract-demo.ipynb](einteract-demo.ipynb) which demonstates subclassing `InteractBase`, using custom widgets, and observing multiple functions through the `@callback` decorator.\r\n- See [Bandstructure Visualizer](https://github.com/asaboor-gh/ipyvasp/blob/d181ba9a1789368c5d8bc1460be849c34dcbe341/ipyvasp/widgets.py#L642) and [KPath Builder](https://github.com/asaboor-gh/ipyvasp/blob/d181ba9a1789368c5d8bc1460be849c34dcbe341/ipyvasp/widgets.py#L935) as comprehensive dashboards.\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An enhanced version of ipywidgets's interactive widgets.",
    "version": "1.3.5",
    "project_urls": {
        "Bug Tracker": "https://github.com/asaboor-gh/einteract/issues",
        "Homepage": "https://github.com/asaboor-gh/einteract"
    },
    "split_keywords": [
        "jupyter",
        " widgets",
        " ipython",
        " interact",
        " interactive"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26a96865f45fe7325c62ebd1561e2bb7dd21e28b2931bba94f0e3d2a56f4572a",
                "md5": "e2b3d7df30ea57cae7de49b3e7d66976",
                "sha256": "e0fd554e7c595302d4741aaeec0335b45860f6e77f642b2af660d53ed822a1bc"
            },
            "downloads": -1,
            "filename": "einteract-1.3.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e2b3d7df30ea57cae7de49b3e7d66976",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.9",
            "size": 6523,
            "upload_time": "2025-07-20T18:05:11",
            "upload_time_iso_8601": "2025-07-20T18:05:11.225246Z",
            "url": "https://files.pythonhosted.org/packages/26/a9/6865f45fe7325c62ebd1561e2bb7dd21e28b2931bba94f0e3d2a56f4572a/einteract-1.3.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "726ec5848b4df90bd8994d9f25dbc2bdca9c5dcaf4e0ce5d54462f311b291b13",
                "md5": "afd384fe15162936a6c47571797bb1eb",
                "sha256": "2059a22ca716ff9666841244b113574fe3b0248472a6a3fa753c6a53c8cd0ff0"
            },
            "downloads": -1,
            "filename": "einteract-1.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "afd384fe15162936a6c47571797bb1eb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7168,
            "upload_time": "2025-07-20T18:05:12",
            "upload_time_iso_8601": "2025-07-20T18:05:12.348468Z",
            "url": "https://files.pythonhosted.org/packages/72/6e/c5848b4df90bd8994d9f25dbc2bdca9c5dcaf4e0ce5d54462f311b291b13/einteract-1.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-20 18:05:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asaboor-gh",
    "github_project": "einteract",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "ipyslides",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        }
    ],
    "lcname": "einteract"
}
        
Elapsed time: 1.37558s