Skip to main content

Declarative coordinated multiple views for Jupyter Widgets

Project description

with-coordination

declarative coordinated multiple views for Jupyter Widgets

pip install with-coordination

usage

import ipywidgets

# create a set of widgets
slider1 = ipywidgets.FloatSlider(description='Slider 1')
slider2 = ipywidgets.FloatSlider(description='Slider 2')
slider3 = ipywidgets.FloatSlider(description='Slider 3')

# prepare an output area with arrangement of widgets
ipywidgets.VBox([slider1, slider2, slider3])
from with_coordination import Coordination

# create a coordination context
with Coordination() as c:

  # define a coordination type
  with c.type("sliderValue") as t:

    # add a scope with a set of widgets
    with t.scope("A", 10) as s:
      # alias maps the widget prop to the coordination type if they are different
      s.view(slider1, alias="value")

    with t.scope("B", 4.0) as s:
      s.view(slider2, alias="value")
      s.view(slider3, alias="value")


  # get the coordination configuration as json
  print(c.to_json()) # b'{"coordinationSpace":{"sliderValue":{"A":10,"B":4.0}},"viewCoordination":{"view_0": ...'

Alternatively, you can use use an existing configuration to create a coordination context.

with open("config.json", "w") as f:
  f.write("""
  {
    "key": 1,
    "coordinationSpace": { "sliderValue": { "A": 0.5, "B": 0.75 } },
    "viewCoordination": {
      "slider1": { "coordinationScopes": { "sliderValue": "A" } },
      "slider2": { "coordinationScopes": { "sliderValue": "B" } },
      "slider3": { "coordinationScopes": { "sliderValue": "B" } }
    }
  }
  """)

with Coordination("config.json") as c:
    c.use_widget(slider1, view_id="slider1", aliases={"value": "sliderValue"})
    c.use_widget(slider2, view_id="slider2", aliases={"value": "sliderValue"})
    c.use_widget(slider3, view_id="slider3", aliases={"value": "sliderValue"})

why

Managing coordinated multiple views is a complex task. This library provides an ergonomic and declarative API to specify how widgets traits should be coordinated.

with-coordination is based on the declarative JSON coordination specification from use-coordination and is designed to work with anywidget.

development

this project is managed using rye.

rye run jupyter lab

rye manages testing, linting, and formatting.

rye test
rye lint
rye format

alternatively you can create a virtual environment and use an development installation. You will need to install jupyterlab.

python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install jupyterlab
jupyter lab

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

with_coordination-0.0.1.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

with_coordination-0.0.1-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

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