-
Notifications
You must be signed in to change notification settings - Fork 42
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
Jupyter integration: UI components for data discovery #170
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6965b00
Show Vue components in Jupyter
m-mohr 5a5c80a
Merge remote-tracking branch 'origin/master' into vue-components
m-mohr 004c077
Update URL for Vue components
m-mohr eb848e6
Add VisualList for processes and collections
m-mohr c2fecba
Better error messages
m-mohr d797803
Fix issues brought up in code review
m-mohr eed2956
Replace String Template with string format
m-mohr f2b9ced
Check existence of scripts in JS itself
m-mohr 61c27d0
Add a separate data parameter for VisualDict/List and move Vue specif…
m-mohr 6bc1e1a
Update URL to Vue Components v2.0.0-beta.2
m-mohr 1accbb3
Update URL to Vue Components v2.0.0-rc.1
m-mohr d8ea1cb
Implement suggestion from code review
m-mohr 05fd41a
Remove JupyterIntegration class and make it a separate method render_…
m-mohr a90354f
Update version number and use minified version
m-mohr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from collections import Mapping | ||
import json | ||
|
||
# These classes are proxies to visualize openEO responses nicely in Jupyter | ||
# To show the actual list or dict in Jupyter, use repr() or print() | ||
|
||
SCRIPT_URL = 'https://cdn.jsdelivr.net/npm/@openeo/[email protected]/assets/openeo.js' | ||
COMPONENT_MAP = { | ||
'file-format': 'format', | ||
'file-formats': 'formats', | ||
'service-type': 'service', | ||
'service-types': 'services', | ||
'udf-runtime': 'runtime', | ||
'udf-runtimes': 'runtimes', | ||
} | ||
|
||
class JupyterIntegration: | ||
|
||
def __init__(self, component: str, data = None, parameters: dict = {}): | ||
self.component = component | ||
self.parameters = parameters | ||
|
||
# Set the data as the corresponding parameter in the Vue components | ||
key = COMPONENT_MAP.get(component, component) | ||
if data != None: | ||
self.parameters[key] = data | ||
|
||
def _repr_html_(self): | ||
# Construct HTML, load Vue Components source files only if the openEO HTML tag is not yet defined | ||
return """ | ||
<script> | ||
if (!window.customElements || !window.customElements.get('openeo-{component}')) {{ | ||
var el = document.createElement('script'); | ||
el.src = "{script}"; | ||
document.head.appendChild(el); | ||
}} | ||
</script> | ||
<openeo-{component}> | ||
<script type="application/json">{props}</script> | ||
</openeo-{component}> | ||
""".format( | ||
script = SCRIPT_URL, | ||
component = self.component, | ||
props = json.dumps(self.parameters) | ||
) | ||
|
||
|
||
class VisualDict(dict, JupyterIntegration): | ||
m-mohr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def __init__(self, component: str, data : dict, parameters: dict = {}): | ||
JupyterIntegration.__init__(self, component, data, parameters) | ||
dict.__init__(self, data) | ||
|
||
|
||
class VisualList(list, JupyterIntegration): | ||
|
||
def __init__(self, component: str, data : list, parameters: dict = {}): | ||
JupyterIntegration.__init__(self, component, data, parameters) | ||
list.__init__(self, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a todo note here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. We could add it to a config file, but we can't and shouldn't get it through other means dynamically. The implementation is bound to the specific version and once we have a stable version 2.0.0 (in one or two weeks) it will be
SCRIPT_URL = 'https://cdn.jsdelivr.net/npm/@openeo/vue-components@2/assets/openeo.js'
, which will cover always the latest version of the 2.x branch and then we won't change it any time soon again as 3.x would be breaking anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep this PR open until we have a 2.0.0 release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or merge now? This will not be released immediately anyway, but it will make it available to other people testing on master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdries Sure, I'm fine with that. Just released another RC for vue-components so that all recent changes are in. Feel free to merge at any time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdries But four hours later 😂 👍