Skip to content

Commit 4da7a2c

Browse files
authored
Add xeus-r to kernels gallery (#60)
* Add `xeus-r` * bump jupyterlite-sphinx * try miniconda * . * updates * bump micromamba * add r notebook * ggplot2 * more deps * wip * add plotting examples * `xeus-r >= 0.7.0` * update deps * update demo notebook * update intro notebook
1 parent e4e1908 commit 4da7a2c

File tree

6 files changed

+408
-63
lines changed

6 files changed

+408
-63
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
- name: Install micromamba
2424
uses: mamba-org/setup-micromamba@v1
2525
with:
26-
micromamba-version: '1.5.8-0'
27-
environment-file: environment.yml
26+
micromamba-version: '2.0.5-0'
27+
environment-file: build-environment.yml
2828
cache-environment: true
2929
- name: Build the JupyterLite site
3030
shell: bash -l {0}

.readthedocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ version: 2
33
build:
44
os: "ubuntu-20.04"
55
tools:
6-
python: "mambaforge-4.10"
6+
python: "miniconda-latest"
77

88
conda:
9-
environment: environment.yml
9+
environment: build-environment.yml
1010

1111
sphinx:
1212
configuration: conf.py

build-environment.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: try-jupyter
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python =3.12
6+
- mamba
7+
- pydata-sphinx-theme
8+
- myst-parser
9+
- bqplot
10+
- ipycanvas >=0.9.1
11+
- ipyleaflet
12+
- ipympl >=0.8.2
13+
- ipywidgets >=8.1.7,<9
14+
- jupyterlab >=4.4.3,<=4.5
15+
- jupyterlab-language-pack-fr-FR
16+
- jupyterlab-language-pack-zh-CN
17+
- jupyterlab-fasta >=3.3.0,<4
18+
- jupyterlab-geojson >=3.4.0,<4
19+
- jupyterlab-tour
20+
- jupyterlab-night
21+
- jupyterlite-core =0.6.0
22+
- jupyterlite-pyodide-kernel =0.6.0
23+
- jupyterlite-sphinx >=0.20.2,<0.21
24+
- jupyterlite-xeus>=4.0.0
25+
- notebook >=7.4.3,<7.5
26+
- pip
27+
- plotly >=6,<7
28+
- pip:
29+
- jupyterlite-xeus-sqlite==0.2.1
30+
- jupyterlab-open-url-parameter >=0.3.0

content/notebooks/Intro.ipynb

Lines changed: 93 additions & 32 deletions
Large diffs are not rendered by default.

content/notebooks/r.ipynb

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"name": "xr",
5+
"display_name": "R 4.4.3 (xr)",
6+
"language": "R"
7+
},
8+
"language_info": {
9+
"codemirror_mode": "",
10+
"file_extension": "R",
11+
"mimetype": "text/x-R",
12+
"name": "R",
13+
"nbconvert_exporter": "",
14+
"pygments_lexer": "",
15+
"version": "4.4.3"
16+
}
17+
},
18+
"nbformat_minor": 4,
19+
"nbformat": 4,
20+
"cells": [
21+
{
22+
"cell_type": "markdown",
23+
"source": "# XEUS-R",
24+
"metadata": {}
25+
},
26+
{
27+
"cell_type": "code",
28+
"source": "R.version",
29+
"metadata": {
30+
"trusted": true,
31+
"vscode": {
32+
"languageId": "r"
33+
}
34+
},
35+
"outputs": [],
36+
"execution_count": null
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"source": "## Internal packages",
41+
"metadata": {}
42+
},
43+
{
44+
"cell_type": "code",
45+
"source": "library(stats)\n\nset.seed(123)\nx <- rnorm(100)\ny <- 2 * x + rnorm(100)\n\n# Linear regression\nmodel <- lm(y ~ x)\nsummary(model)",
46+
"metadata": {
47+
"trusted": true,
48+
"vscode": {
49+
"languageId": "r"
50+
}
51+
},
52+
"outputs": [],
53+
"execution_count": null
54+
},
55+
{
56+
"cell_type": "code",
57+
"source": "A <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, ncol = 2)\n\n# Singular value decomposition\nsvd_result <- La.svd(A)\n\nprint(svd_result)",
58+
"metadata": {
59+
"trusted": true,
60+
"vscode": {
61+
"languageId": "r"
62+
}
63+
},
64+
"outputs": [],
65+
"execution_count": null
66+
},
67+
{
68+
"cell_type": "code",
69+
"source": "A <- matrix(c(4, 1, 1, 3), nrow = 2, byrow = TRUE)\n\n# Eigen decomposition\neigen_result <- eigen(A)\n\nprint(eigen_result$values)\n\nprint(eigen_result$vectors)",
70+
"metadata": {
71+
"trusted": true,
72+
"vscode": {
73+
"languageId": "r"
74+
}
75+
},
76+
"outputs": [],
77+
"execution_count": null
78+
},
79+
{
80+
"cell_type": "code",
81+
"source": "# Example positive-definite matrix\nA <- matrix(c(4, 1, 1, 3), nrow = 2, byrow = TRUE)\n\n# Cholesky decomposition\nchol_result <- chol(A)\n\nprint(chol_result)",
82+
"metadata": {
83+
"trusted": true,
84+
"vscode": {
85+
"languageId": "r"
86+
}
87+
},
88+
"outputs": [],
89+
"execution_count": null
90+
},
91+
{
92+
"cell_type": "code",
93+
"source": "B <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, ncol = 2)\nC <- matrix(c(7, 8, 9, 10, 11, 12), nrow = 3, ncol = 2)\n\n# Perform matrix multiplication using BLAS\nresult <- crossprod(B, C)\n\nprint(result)",
94+
"metadata": {
95+
"trusted": true,
96+
"vscode": {
97+
"languageId": "r"
98+
}
99+
},
100+
"outputs": [],
101+
"execution_count": null
102+
},
103+
{
104+
"cell_type": "code",
105+
"source": "# Fibonacci sequence\nfibonacci_loop <- function(n) {\n a <- 0\n b <- 1\n\n for (i in 1:n) {\n fib <- a\n cat(fib, \"\\n\")\n a <- b\n b <- fib + b\n }\n return(a)\n}\n\nfibonacci_loop(10)",
106+
"metadata": {
107+
"trusted": true,
108+
"vscode": {
109+
"languageId": "r"
110+
}
111+
},
112+
"outputs": [],
113+
"execution_count": null
114+
},
115+
{
116+
"cell_type": "markdown",
117+
"source": "## Plotting",
118+
"metadata": {}
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"source": "Some of the following R Code was pulled from https://www.statmethods.net/advgraphs/ggplot2.html, and updated to use newer `ggplot2` APIs.",
123+
"metadata": {}
124+
},
125+
{
126+
"cell_type": "code",
127+
"source": "# ggplot2 examples\nlibrary(ggplot2)",
128+
"metadata": {
129+
"vscode": {
130+
"languageId": "r"
131+
},
132+
"trusted": true
133+
},
134+
"outputs": [],
135+
"execution_count": null
136+
},
137+
{
138+
"cell_type": "code",
139+
"source": "# create factors with value labels\nmtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),\n \tlabels=c(\"3gears\",\"4gears\",\"5gears\"))\nmtcars$am <- factor(mtcars$am,levels=c(0,1),\n \tlabels=c(\"Automatic\",\"Manual\"))\nmtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),\n labels=c(\"4cyl\",\"6cyl\",\"8cyl\"))",
140+
"metadata": {
141+
"vscode": {
142+
"languageId": "r"
143+
},
144+
"trusted": true
145+
},
146+
"outputs": [],
147+
"execution_count": null
148+
},
149+
{
150+
"cell_type": "code",
151+
"source": "# Kernel density plots for mpg\n# grouped by number of gears (indicated by color)\nggplot(mtcars, aes(x = mpg, fill = gear)) +\n geom_density(alpha = 0.5) +\n labs(\n title = \"Distribution of Gas Milage\",\n x = \"Miles Per Gallon\",\n y = \"Density\",\n fill = \"Gears\"\n )",
152+
"metadata": {
153+
"vscode": {
154+
"languageId": "r"
155+
},
156+
"trusted": true
157+
},
158+
"outputs": [],
159+
"execution_count": null
160+
},
161+
{
162+
"cell_type": "code",
163+
"source": "# Scatterplot of mpg vs. hp for each combination of gears and cylinders\n# in each facet, transmission type is represented by shape and color\nggplot(mtcars, aes(x = hp, y = mpg, shape = am, color = am)) +\n geom_point(size = 3) +\n facet_grid(gear ~ cyl) +\n labs(\n x = \"Horsepower\",\n y = \"Miles per Gallon\",\n shape = \"Transmission\",\n color = \"Transmission\"\n )",
164+
"metadata": {
165+
"vscode": {
166+
"languageId": "r"
167+
},
168+
"trusted": true
169+
},
170+
"outputs": [],
171+
"execution_count": null
172+
},
173+
{
174+
"cell_type": "code",
175+
"source": "# Separate regressions of mpg on weight for each number of cylinders\nggplot(mtcars, aes(x = wt, y = mpg, color = cyl)) +\n geom_point() +\n geom_smooth(method = \"lm\", formula = y ~ x) +\n labs(\n title = \"Regression of MPG on Weight\",\n x = \"Weight\",\n y = \"Miles per Gallon\",\n color = \"Cylinders\"\n )",
176+
"metadata": {
177+
"vscode": {
178+
"languageId": "r"
179+
},
180+
"trusted": true
181+
},
182+
"outputs": [],
183+
"execution_count": null
184+
},
185+
{
186+
"cell_type": "code",
187+
"source": "# Boxplots of mpg by number of gears\n# observations (points) are overlayed and jittered\nggplot(mtcars, aes(x = gear, y = mpg, fill = gear)) +\n geom_boxplot() +\n geom_jitter(width = 0.2) +\n labs(\n title = \"Mileage by Gear Number\",\n x = \"\",\n y = \"Miles per Gallon\",\n fill = \"Gears\"\n )",
188+
"metadata": {
189+
"vscode": {
190+
"languageId": "r"
191+
},
192+
"trusted": true
193+
},
194+
"outputs": [],
195+
"execution_count": null
196+
},
197+
{
198+
"cell_type": "markdown",
199+
"source": "## Other R Packages",
200+
"metadata": {
201+
"vscode": {
202+
"languageId": "plaintext"
203+
}
204+
}
205+
},
206+
{
207+
"cell_type": "code",
208+
"source": "library(RColorBrewer)\npalette <- brewer.pal(8, \"Set3\")\nprint(palette)",
209+
"metadata": {
210+
"trusted": true,
211+
"vscode": {
212+
"languageId": "r"
213+
}
214+
},
215+
"outputs": [],
216+
"execution_count": null
217+
},
218+
{
219+
"cell_type": "code",
220+
"source": "library(crayon)\n\n# Create colorful text\nred_text <- red(\"This is red text\")\ngreen_text <- green(\"This is green text\")\nblue_text <- blue(\"This is blue text\")\nbold_text <- bold(\"This is bold text\")\nunderline_text <- underline(\"This is underlined text\")\n\ncat(red_text, \"\\n\")\ncat(green_text, \"\\n\")\ncat(blue_text, \"\\n\")\ncat(bold_text, \"\\n\")\ncat(underline_text, \"\\n\")",
221+
"metadata": {
222+
"trusted": true,
223+
"vscode": {
224+
"languageId": "r"
225+
}
226+
},
227+
"outputs": [],
228+
"execution_count": null
229+
},
230+
{
231+
"cell_type": "code",
232+
"source": "library(htmltools)\n\n# Create HMTL elements\ntitle <- tags$title(\"My HTML Page\")\nheader <- tags$h1(\"Hello there!\")\nparagraph <- tags$p(\"This is a paragraph created using htmltools.\")\nlist_items <- tags$ul(tags$li(\"Item 1\"), tags$li(\"Item 2\"), tags$li(\"Item 3\"))\n\n# Combine elements into an HTML document\nhtml_doc <- tags$html(\n tags$head(title),\n tags$body(\n header,\n paragraph,\n list_items\n )\n)\n\nprint(html_doc)",
233+
"metadata": {
234+
"trusted": true,
235+
"vscode": {
236+
"languageId": "r"
237+
}
238+
},
239+
"outputs": [],
240+
"execution_count": null
241+
},
242+
{
243+
"cell_type": "code",
244+
"source": "library(farver)\n\n# Define a color in RBG space\nrgb_color <- matrix(c(255, 0, 0), ncol = 3)\n\n# Convert RGB to HSV\nhsv_color <- convert_colour(rgb_color, \"rgb\", \"hsv\")\n\n# Convert RGB to LAB\nlab_color <- convert_colour(rgb_color, \"rgb\", \"lab\")\n\nprint(rgb_color)\nprint(hsv_color)\nprint(lab_color)",
245+
"metadata": {
246+
"trusted": true,
247+
"vscode": {
248+
"languageId": "r"
249+
}
250+
},
251+
"outputs": [],
252+
"execution_count": null
253+
},
254+
{
255+
"cell_type": "code",
256+
"source": "",
257+
"metadata": {
258+
"vscode": {
259+
"languageId": "r"
260+
},
261+
"trusted": true
262+
},
263+
"outputs": [],
264+
"execution_count": null
265+
},
266+
{
267+
"cell_type": "code",
268+
"source": "",
269+
"metadata": {
270+
"trusted": true
271+
},
272+
"outputs": [],
273+
"execution_count": null
274+
}
275+
]
276+
}

environment.yml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
name: try-jupyter
1+
name: xeus-r-kernel
22
channels:
3-
- conda-forge
3+
- https://repo.prefix.dev/emscripten-forge-dev
4+
- https://repo.prefix.dev/conda-forge
45
dependencies:
5-
- python =3.12
6-
- mamba
7-
- pydata-sphinx-theme
8-
- myst-parser
9-
- bqplot
10-
- ipycanvas >=0.9.1
11-
- ipyleaflet
12-
- ipympl >=0.8.2
13-
- ipywidgets >=8.1.7,<9
14-
- jupyterlab >=4.4.3,<=4.5
15-
- jupyterlab-language-pack-fr-FR
16-
- jupyterlab-language-pack-zh-CN
17-
- jupyterlab-fasta >=3.3.0,<4
18-
- jupyterlab-geojson >=3.4.0,<4
19-
- jupyterlab-tour
20-
- jupyterlab-night
21-
- jupyterlite-core =0.6.0
22-
- jupyterlite-pyodide-kernel =0.6.0
23-
- jupyterlite-sphinx >=0.20.2,<0.21
24-
- notebook >=7.4.3,<7.5
25-
- pip
26-
- plotly >=6,<7
27-
- pip:
28-
- jupyterlite-xeus-sqlite==0.2.1
29-
- jupyterlab-open-url-parameter >=0.3.0
6+
- xeus-r >= 0.7.0
7+
- r-ggplot2

0 commit comments

Comments
 (0)