Comments (4)
Regarding VS Code now supports 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
.ipywidgets 8
🎉
from eerepr.
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.
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.
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)
- Property order HOT 1
- PyPI and conda-forge HOT 2
- Collapsing identical reprs broken by caching HOT 2
- Fix `ee.List.shuffle`
- Add `MAX_REPR_MB` config
- Try minifying HOT 1
- Shrink reprs
- Options for python_requires directive? HOT 2
- Improve performance HOT 2
- Support for Python 3.7 HOT 1
- Null geometry repr bug HOT 4
- Add CI tests
- Test with JSON instead of server data
- Simplify packaging and drop 3.7 support
- Add pre-commit hooks
- Check for unused cached test data
- Ideas for limits
- Document using `IPython.display` for manual repr display HOT 1
- Fix failing CI
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eerepr.