-
Notifications
You must be signed in to change notification settings - Fork 3
Try using async widgets #21
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
ipywidgets supports async widgets via threading. Rather than waiting for data, turning it into HTML, and directly displaying the HTML, I could return a loading HTML 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 alongside geemap then that's not a big issue. Other considerations would be:
Can I throw all the JS and CSS into theHTMLwidget like I currently do, or do I need to handle that differently?- No.
HTMLwidgets do not run scripts.
- No.
- Would reprs inside an
HTMLwidget display correctly when rendered statically like they currently do? That's not a dealbreaker, but it would be nice. - Are there performance drawbacks in rendering time?
- What will the
ipywidgetscompatibility be? I've had issues in the past withipywidgets>7, especially in Jupyter Lab, so ideally this would work in version 7 or 8. - Calling
_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:
def _ipython_display_(obj: ee.Element):
"""Display an Earth Engine object in an async HTML widget"""
html = ipywidgets.HTML("<span>Loading...</span>")
threading.Thread().start(build_repr, args=(obj, html))
return html._ipython_display_()
def _build_repr(obj: ee.Element, html: ipywidgets.HTML) -> None:
"""Format an HTML repr string and add it to an HTML widget"""
info = obj.getInfo()
rep = _format_repr(info)
html.value = repReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request