Skip to content

Add copy/download buttons to results table widgets #602

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

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
- Path: 02-Neptune-ML > 03-Sample-Applications > 04-Telco-Networks
- Added KMS encryption support to NeptuneDB Notebook CloudFormation template ([Link to PR](https://github.com/aws/graph-notebook/pull/590))
- Added warnings for usage of `%%oc` with incompatible Neptune Analytics parameters ([Link to PR](https://github.com/aws/graph-notebook/pull/599))
- Added download and copy buttons to results table widgets ([Link to PR](https://github.com/aws/graph-notebook/pull/602))
- Improved handling of mixed type Gremlin results ([Link to PR](https://github.com/aws/graph-notebook/pull/592))
- Upgraded `rdflib` to 7.0.0 and `SPARQLWrapper` to 2.0.0 ([Link to PR](https://github.com/aws/graph-notebook/pull/596))
- Upgraded `requests` to 2.32.x ([Link to PR](https://github.com/aws/graph-notebook/pull/600))
Expand Down
101 changes: 97 additions & 4 deletions src/graph_notebook/magics/graph_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
$(td).css('font-size', '12px');
}
"""
SPARQL_RESULTS_FILENAME = "sparql_results"
GREMLIN_RESULTS_FILENAME = "gremlin_results"
OC_RESULTS_FILENAME = "oc_results"
LOAD_IDS_FILENAME = "load_ids"
RESULTS_EXPORT_OPTIONS = {
"columns": 1,
"modifier": {
"header": False,
"page": "all",
"order": "current",
"search": "applied",
}
}

JSON_FORMAT = "json"
PANDAS_FORMATS = ["pd", "pandas", "df", "dataframe"]
Expand Down Expand Up @@ -916,7 +929,27 @@ def sparql(self, line='', cell='', local_ns: dict = None):
scrollCollapse=sparql_scrollCollapse,
lengthMenu=[final_pagination_options, final_pagination_menu],
pageLength=visible_results,
buttons=["pageLength"]
buttons=[
"pageLength",
{
"extend": "copyHtml5",
"text": "Copy",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "csvHtml5",
"title": SPARQL_RESULTS_FILENAME,
"text": "Download CSV",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "excelHtml5",
"filename": SPARQL_RESULTS_FILENAME,
"title": None,
"text": "Download XLSX",
"exportOptions": RESULTS_EXPORT_OPTIONS
}
]
)
elif first_tab_html != "":
with first_tab_output:
Expand Down Expand Up @@ -1269,7 +1302,27 @@ def gremlin(self, line, cell, local_ns: dict = None):
scrollCollapse=gremlin_scrollCollapse,
lengthMenu=[final_pagination_options, final_pagination_menu],
pageLength=visible_results,
buttons=["pageLength"]
buttons=[
"pageLength",
{
"extend": "copyHtml5",
"text": "Copy",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "csvHtml5",
"title": GREMLIN_RESULTS_FILENAME,
"text": "Download CSV",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "excelHtml5",
"filename": GREMLIN_RESULTS_FILENAME,
"title": None,
"text": "Download XLSX",
"exportOptions": RESULTS_EXPORT_OPTIONS
}
]
)
else: # Explain/Profile
display(HTML(first_tab_html))
Expand Down Expand Up @@ -2238,7 +2291,27 @@ def load_ids(self, line, local_ns: dict = None):
scrollCollapse=True,
lengthMenu=[DEFAULT_PAGINATION_OPTIONS, DEFAULT_PAGINATION_MENU],
pageLength=10,
buttons=["pageLength"]
buttons=[
"pageLength",
{
"extend": "copyHtml5",
"text": "Copy",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "csvHtml5",
"title": LOAD_IDS_FILENAME,
"text": "Download CSV",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "excelHtml5",
"filename": LOAD_IDS_FILENAME,
"title": None,
"text": "Download XLSX",
"exportOptions": RESULTS_EXPORT_OPTIONS
}
]
)

with raw_output:
Expand Down Expand Up @@ -3267,7 +3340,27 @@ def handle_opencypher_query(self, line, cell, local_ns):
scrollCollapse=oc_scrollCollapse,
lengthMenu=[final_pagination_options, final_pagination_menu],
pageLength=visible_results,
buttons=["pageLength"]
buttons=[
"pageLength",
{
"extend": "copyHtml5",
"text": "Copy",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "csvHtml5",
"title": OC_RESULTS_FILENAME,
"text": "Download CSV",
"exportOptions": RESULTS_EXPORT_OPTIONS
},
{
"extend": "excelHtml5",
"filename": OC_RESULTS_FILENAME,
"title": None,
"text": "Download XLSX",
"exportOptions": RESULTS_EXPORT_OPTIONS
}
]
)
elif first_tab_html != "":
with first_tab_output:
Expand Down
Loading