Skip to content

Commit 7bdc434

Browse files
committed
widgets: add itables and pygwalker
1 parent 236a88d commit 7bdc434

File tree

5 files changed

+124
-52
lines changed

5 files changed

+124
-52
lines changed

data/itables/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: itables
2+
description: Interactive tables in Jupyter and marimo notebooks
3+
repository: https://github.com/mwouts/itables
4+
pypi: itables
5+
environments: [marimo, jupyter]
6+
tags:
7+
- table
8+
- pandas
9+
- interactive
10+
- jupyter
11+
notebookCode: |
12+
import pandas as pd
13+
import anywidget
14+
15+
from itables.widget import ITable
16+
17+
df = pd.read_json(
18+
"https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json"
19+
)
20+
21+
ITable(df)

data/pygwalker/config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: PyGWalker
2+
description: Turn your pandas dataframe into an interactive UI for visual analysis
3+
homePageUrl: https://github.com/Kanaries/pygwalker
4+
environments: [marimo, jupyter]
5+
githubRepo: Kanaries/pygwalker
6+
tags: [visualization, data analysis, pandas, tableau]
7+
packageName: pygwalker
8+
notebookCode: |
9+
import pygwalker as pyg
10+
import pandas as pd
11+
df = pd.read_csv("https://raw.githubusercontent.com/Kanaries/pygwalker/main/examples/data/data.csv")
12+
pyg.walk(df)

gallery/app/utils/notebook.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import type { BuiltWithAnyWidget } from "~/model/types";
2+
import { dedent } from "ts-dedent";
23

34
export function resolveNotebookURL(widget: BuiltWithAnyWidget) {
45
const queryParams = new URLSearchParams();
56

67
if (widget.notebookUrl) {
78
queryParams.set("src", widget.notebookUrl);
89
} else if (widget.notebookCode) {
9-
queryParams.set("code", encodeURIComponent(widget.notebookCode));
10+
queryParams.set(
11+
"code",
12+
encodeURIComponent(createNotebookFromCode(widget.notebookCode)),
13+
);
1014
} else if (widget.githubRepo) {
1115
let guessPackageName =
1216
widget.packageName || widget.githubRepo.split("/").pop();
@@ -44,3 +48,28 @@ async def _():
4448
embedUrl: `https://marimo.app?${embedQueryParams.toString()}`,
4549
};
4650
}
51+
52+
function createNotebookFromCode(code: string) {
53+
if (code.includes("app = marimo.App()")) {
54+
return dedent(code);
55+
}
56+
57+
const dedentedCode = dedent(code);
58+
return `
59+
import marimo
60+
61+
app = marimo.App()
62+
63+
@app.cell
64+
async def _():
65+
${indentCode(dedentedCode, " ")}
66+
return
67+
`;
68+
}
69+
70+
function indentCode(code: string, indent: string) {
71+
return code
72+
.split("\n")
73+
.map((line) => `${indent}${line}`)
74+
.join("\n");
75+
}

gallery/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"react-dom": "^19.0.0",
2727
"tailwind-merge": "^3.0.2",
2828
"tailwindcss-animate": "^1.0.7",
29+
"ts-dedent": "^2.2.0",
2930
"yaml": "^2.7.0",
3031
"zod": "^3.24.2"
3132
},
@@ -40,8 +41,8 @@
4041
"typescript": "^5.8.2",
4142
"vite": "^6.2.1",
4243
"vite-tsconfig-paths": "^5.1.4",
43-
"wrangler": "3.114.0",
44-
"vitest": "^3.0.8"
44+
"vitest": "^3.0.8",
45+
"wrangler": "3.114.0"
4546
},
4647
"engines": {
4748
"node": ">=20.0.0"

0 commit comments

Comments
 (0)