-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add a notebook to view tables of json interactively #45
Open
willingc
wants to merge
1
commit into
napari:main
Choose a base branch
from
willingc:notebook-tables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,28 @@ | ||
# Run notebooks | ||
|
||
## Create virtual environment | ||
|
||
Make sure that uv is installed (though it should work with only pip) | ||
|
||
```sh | ||
uv venv | ||
source .venv/bin/activate | ||
``` | ||
|
||
## Install dependencies | ||
|
||
From the `notebooks` directory: | ||
|
||
```sh | ||
uv pip install -r requirements-nb.txt | ||
``` | ||
|
||
## Start jupyterlab | ||
|
||
```sh | ||
jupyter lab | ||
``` | ||
|
||
## Tables example | ||
|
||
Uses polars, great tables, and itables to display a json data file. |
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,8 @@ | ||
-r ../requirements.txt | ||
|
||
great_tables | ||
itables | ||
jupyter | ||
pandas | ||
polars | ||
|
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,38 @@ | ||
<table id="itables_e557a59b_2a20_4ffc_b322_2972af0891af" class="display nowrap" data-quarto-disable-processing="true" style="table-layout:auto;width:auto;margin:auto;caption-side:bottom"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
|
||
<th>name</th> | ||
<th>version</th> | ||
<th>display_name</th> | ||
<th>summary</th> | ||
<th>author</th> | ||
<th>license</th> | ||
<th>home_page</th> | ||
</tr> | ||
</thead><tbody><tr> | ||
<td style="vertical-align:middle; text-align:left"> | ||
|
||
Loading ITables v2.2.5 from the internet... | ||
(need <a href=https://mwouts.github.io/itables/troubleshooting.html>help</a>?)</td> | ||
</tr></tbody> | ||
</table> | ||
<link href="https://www.unpkg.com/[email protected]/dt_bundle.css" rel="stylesheet"> | ||
<script type="module"> | ||
import {DataTable, jQuery as $} from 'https://www.unpkg.com/[email protected]/dt_bundle.js'; | ||
|
||
document.querySelectorAll("#itables_e557a59b_2a20_4ffc_b322_2972af0891af:not(.dataTable)").forEach(table => { | ||
if (!(table instanceof HTMLTableElement)) | ||
return; | ||
|
||
// Define the table data | ||
const data = [["acquifer-napari", "0.0.2", "acquifer-napari", "Loader plugin for napari, to load Acquifer Imaging Machine datasets in napari, using dask for efficient lazy data-loading.", "Laurent Thomas", "GPL-3.0-only", null], ["ads_napari", "0.0.5", "ads_napari", "Axon/Myelin segmentation using AI", "NeuroPoly Lab", null, null], ["affinder", "0.4.0", "affinder", "Quickly find the affine matrix mapping one image to another using manual correspondence points annotation", "Juan Nunez-Iglesias", "BSD-3", "https://github.com/jni/affinder"]]; | ||
|
||
// Define the dt_args | ||
let dt_args = {"layout": {"topStart": null, "topEnd": null, "bottomStart": null, "bottomEnd": null}, "order": [], "warn_on_selected_rows_not_rendered": true}; | ||
dt_args["data"] = data; | ||
|
||
|
||
new DataTable(table, dt_args); | ||
}); | ||
</script> |
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,159 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "df688416-8513-47e1-b836-5f95a9b87be4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# file path depends on what the current directory is and where you launched jupyter lab\n", | ||
"# This filename assumes you started jupyterlab from the notebook directory\n", | ||
"DATA_FILE = \"../public/summary.json\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3b903d94-27f6-4d0a-93f0-e07e2501de4e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Let's use polars over pandas for performance\n", | ||
"import polars as pl" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "82c76b46-aaec-46e1-a3ca-b491cd3a9988", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# import great_tables for nicely styled tables\n", | ||
"from great_tables import GT, md, html" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "34881b4e-0ca9-4577-b14a-8b8ad4305d38", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# import and initialize itables for interactive tables\n", | ||
"from itables import init_notebook_mode, show\n", | ||
"init_notebook_mode(all_interactive=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c01c8178-bc2d-4e7d-a9fb-217122121df9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Prevent itables from downsampling data\n", | ||
"import itables.options as opt\n", | ||
"opt.maxBytes = \"512KB\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b26c0b4c-8452-4f5b-9d51-855a43e422c4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df_summary = pl.read_json(DATA_FILE)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "27b9f28a-9627-4155-a5f3-ecc9fc130ba3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"Polars default output\")\n", | ||
"df_summary.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "35f7229a-49d0-481d-abf5-9b5866933395", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"Great Tables default output\")\n", | ||
"GT(df_summary.head())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "99b4939d-a0de-4932-bd72-09657d6caf9e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"Interactive table default\")\n", | ||
"show(df_summary)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0060ed2c-34b2-4a11-b125-61cb517f50cf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Output as an html page (Quarto is also an option)\n", | ||
"from IPython.display import HTML, display\n", | ||
"\n", | ||
"from itables import to_html_datatable\n", | ||
"\n", | ||
"html = to_html_datatable(df_summary.head(3), display_logo_when_loading=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "37cebbda-6896-46f3-bd0a-43e90232439c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(html)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3c5c10c9-58a9-4163-98a7-3376bd73cbae", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.13.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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.
Is this just to show what the HTML from the notebook would look like in HTML? I'm not sure I grok how I should be using it. Also I'm not sure if we need to mention anywhere that you need to click
Trust HTML
if you're viewing this in jupyter labThere 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 could remove the HTML. It was more for you. It could be embedded into a page in hublite.
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.
Got it, let's remove for now and then we can merge this as an example. Next step would be to add a table showing the manifest information effectively. I think that would be very useful.