Giter VIP home page Giter VIP logo

Comments (4)

aazuspan avatar aazuspan commented on August 25, 2024

Regarding ipywidgets compatibility, VS Code doesn't currently support >7 (microsoft/vscode-jupyter#8552). That's okay assuming I can get everything working in 7.7.2. VS Code now supports ipywidgets 8 🎉

from eerepr.

aazuspan avatar aazuspan commented on August 25, 2024

Roadblock: ipywidgets doesn't support running Javascript within an HTML widget (jupyter-widgets/ipywidgets#3079), so this is dead in the water until a) that changes or b) I can get a pure CSS solution for collapsing, which is pending widespread support of the has selector (see #5).

from eerepr.

aazuspan avatar aazuspan commented on August 25, 2024

We can work around the limited functionality of the HTML widget by using a different widget where collapsing is built-in.

ipytree has all the functionality I need and would dramatically simplify the process of building the repr, but performance seems to be very slow. A client-side image collection with three images took about 4.8s to build with ipytree compared to around 4ms with HTML (~1000x slower), and there was also a longer delay in displaying the widget that I didn't measure. The prototype code I tested is below.

from ipytree import Tree, Node
from eerepr.html import _build_label


def build_node(obj):
    if isinstance(obj, list):
        obj_str = str(obj)
        if len(obj_str) > 50:
            obj_str = f"List ({len(obj)} objects)"
        
        node = Node(obj_str, opened=False)
        for item in obj:
            sub_node = build_node(item)
            node.add_node(sub_node)

    elif isinstance(obj, dict):
        obj_str = _build_label(obj)

        node = Node(obj_str, opened=False)
        for k, v in obj.items():
            key_node = build_node(k)
            value_node = build_node(v)
            key_node.add_node(value_node)
            node.add_node(key_node)

    else:
        node = Node(str(obj), opened=False)

    return node

def ipytree_repr(obj):
    """Recursively build an ipytree.Tree from an object."""
    tree = Tree(stripes=True)
    
    node = build_node(obj)
    tree.add_node(node)

    return tree

For reference, with the test below...

info = ee.ImageCollection("COPERNICUS/S2_SR").limit(3).getInfo()
ipytree_repr(info)

...the build_node function gets called 2655 times. That's a lot, but not enough to where overhead from Python looping, function calls, or instantiation should cause a ~1000x slowdown, so the bottleneck may be within ipytree. I should do some more careful benchmarking and profiling to get a better idea of whether there's room for optimization.

Another option is building a custom widget. I've experimented some with anywidget by building a custom EEReprWidget class that is initialized with an Earth Engine object, displays a loading spinner while server-side info is fetched, then sets and renders HTML content in a div built by the _esm hook. This gave me performance comparable with a pure HTML repr with the ability for async loading. It will take some more work to fix some bugs and incompatibilities between ipywidgets versions and Jupyter environments, and I should consider building it without anywidget to save the dependency, but I think this is going to be the solution.

from eerepr.

aazuspan avatar aazuspan commented on August 25, 2024

It will take some more work to fix some bugs and incompatibilities between ipywidgets versions and Jupyter environments

Note that ipywidgets 8 support was finally added to VS Code, which should make this a little less painful!

from eerepr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.