Skip to content

Conversation

@manzt
Copy link
Owner

@manzt manzt commented Jul 20, 2023

Fixes #193. This can be useful for creating container widgets and avoids exposing more backbone/jupyter-widgets internals.

import anywidget
import ipywidgets as ipw
import traitlets

class Box(anywidget.AnyWidget):
    _esm = """
    async function unpack_models(model_ids, manager) {
        return Promise.all(
            model_ids.map(id => manager.get_model(id.slice("IPY_MODEL_".length)))
        );
    }
    export async function render({ model, el }) {
       let model_ids = model.get("children");
        let children_models = await unpack_models(model_ids, model.widget_manager);
        for (let model of children_models) {
            let child_view = await model.widget_manager.create_view(model);
            el.appendChild(child_view.el);
        }
    }
    """
    children = traitlets.List(trait=traitlets.Instance(ipw.DOMWidget)).tag(sync=True, **ipw.widget_serialization)

Box(children=[ipw.IntProgress(), ipw.IntSlider()])

@netlify
Copy link

netlify bot commented Jul 20, 2023

Deploy Preview for anywidget canceled.

Name Link
🔨 Latest commit b48db57
🔍 Latest deploy log https://app.netlify.com/sites/anywidget/deploys/64b96e93ffdf42000825d170

@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Merging #194 (b48db57) into main (fa84359) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #194   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files           8        8           
  Lines         424      424           
=======================================
  Hits          416      416           
  Misses          8        8           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@manzt manzt force-pushed the manzt/widget_manager branch from c3b4feb to b48db57 Compare July 20, 2023 17:27
@manzt manzt merged commit b9fde96 into main Jul 20, 2023
@manzt manzt deleted the manzt/widget_manager branch July 20, 2023 18:06
@github-actions github-actions bot mentioned this pull request Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose AnyView object to widget.render()

2 participants