-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try using async widgets #21
Comments
|
Roadblock: |
We can work around the limited functionality of the 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 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 Another option is building a custom widget. I've experimented some with anywidget by building a custom |
Note that ipywidgets 8 support was finally added to VS Code, which should make this a little less painful! |
ipywidgets
supports async widgets via threading. Rather than waiting for data, turning it into HTML, and directly displaying the HTML, I could return a loadingHTML
widget and use threading to update the widget contents once data is retrieved from the server and formatted. This would make the experience more similar to the code editor by not blocking the entire kernel.The main downside would be adding a dependency on
ipywidgets
, but if most users are using this alongsidegeemap
then that's not a big issue. Other considerations would be:Can I throw all the JS and CSS into theHTML
widget like I currently do, or do I need to handle that differently?HTML
widgets do not run scripts.HTML
widget display correctly when rendered statically like they currently do? That's not a dealbreaker, but it would be nice.ipywidgets
compatibility be? I've had issues in the past withipywidgets>7
, especially in Jupyter Lab, so ideally this would work in version 7 or 8._repr_html_
should return an HTML string, not a widget, so I think I would need to use_ipython_display_
or_repr_mimebundle_
instead and return the corresponding method from the associated widget.Here's a rough implementation idea:
The text was updated successfully, but these errors were encountered: