An enhanced version of ipywidgets's interactive widgets.
Project description
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 which also provides rich content representations.
See code of this simple yet fully customizable dashboard on binder
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 .
Features
- InteractBase: Create interactive dashboard applications with minimal code by extending the
InteractBaseclass and defining methods with the@callbackdecorator. - Custom Widgets:
- Included custom built widgets for enhanced interaction.
- Pass any DOMWidget as a parameter to
interact/interactivefunctions unlike defaultipywidgets.interactivebehavior. - Observe any trait of the widget by
'widget_name.trait_name'where'widget_name'is assigned to awidget/fixed(widget)in control parameters, OR'.trait_name'iftrait_nameexists on instance of interactive. - You can use '.fullscreen' to detect fullscreen change and do actions based on that.
- Add
ipywidgets.Buttonto hold callbacks which use it as paramter for a click
- Plotly Integration: Modified plotly support with additional traits like
selectedandclicked - Matplotlib Support: Convert matplotlib plots to HTML format using
plt2html - Event Callbacks: Easy widget event handling with the
@callbackdecorator inside the subclass ofInteractBaseor multiple functions ininteract/interactivefunctions. - 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',
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'))
Comprehensive Examples
- Check out the einteract-demo.ipynb which demonstates subclassing
InteractBase, using custom widgets, and observing multiple functions through the@callbackdecorator. - See Bandstructure Visualizer and KPath Builder as comprehensive dashboards.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file einteract-1.3.0.tar.gz.
File metadata
- Download URL: einteract-1.3.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f13fed056ff1d6ed73decd83c48084d76f683d6a6202aad25587ad608625c7b0
|
|
| MD5 |
5b7e65aadc719a98b55c3bba3216b1f6
|
|
| BLAKE2b-256 |
deb847d61ac085283c945ff366705191d39a18f46871060a8fdca0f36e6f67ec
|
File details
Details for the file einteract-1.3.0-py2.py3-none-any.whl.
File metadata
- Download URL: einteract-1.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4784940586a18eb48b1f572381a5f59a151759447d01d021805483b48346157
|
|
| MD5 |
34878a1fe460072666e4bfb627f810f1
|
|
| BLAKE2b-256 |
1e096cb17451923bff3096b660d0731f3abccf6ae397c2eff927c3111dbf855b
|