Skip to content

Commit 09601bb

Browse files
committed
feat(codespace): adapt nasa example to inc. rstudio + welcome message
1 parent 10fd99d commit 09601bb

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed

.devcontainer.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

.devcontainer/.devcontainer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*Source: Adapted from https://github.com/boettiger-lab/nasa-topst-env-justice (MIT)*/
2+
3+
{
4+
"name": "RStudio with Quarto",
5+
"image": "ghcr.io/rocker-org/devcontainer/tidyverse:4.4",
6+
"waitFor": "onCreateCommand",
7+
8+
"features": {
9+
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {}
10+
},
11+
12+
"customizations": {
13+
"codespaces": {
14+
"openFiles": ["README.md"]
15+
},
16+
"vscode": {
17+
"settings": {
18+
"r.rterm.linux": "/usr/local/bin/radian",
19+
"r.bracketedPaste": true,
20+
"r.plot.useHttpgd": true,
21+
"[r]": {
22+
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\\\|;:'\\\",<>/?"
23+
}
24+
},
25+
"extensions": [
26+
"REditorSupport.r",
27+
"rdebugger.r-debugger",
28+
"quarto.quarto",
29+
"ms-toolsai.jupyter",
30+
"ms-python.python"
31+
]
32+
}
33+
},
34+
35+
"forwardPorts": [8787],
36+
"portsAttributes": {
37+
"8787": {
38+
"label": "RStudio",
39+
"requireLocalPort": true,
40+
"onAutoForward": "openBrowser"
41+
}
42+
},
43+
44+
"onCreateCommand": "bash .devcontainer/setup.sh",
45+
"postAttachCommand": "bash .devcontainer/welcome.sh",
46+
47+
"remoteUser": "rstudio"
48+
}

.devcontainer/setup.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Source: Adapted from https://github.com/boettiger-lab/nasa-topst-env-justice (MIT)
2+
3+
#!/usr/bin/env bash
4+
set -euo pipefail
5+
6+
# Ensure RStudio runs without password inside Codespace
7+
if [ -f /etc/rstudio/disable_auth_rserver.conf ]; then
8+
sudo cp /etc/rstudio/disable_auth_rserver.conf /etc/rstudio/rserver.conf
9+
fi
10+
11+
# Make sure USER is rstudio so RStudio knows who to log in
12+
sudo bash -c 'echo "USER=rstudio" >> /etc/environment'
13+
14+
# Start RStudio Server in the background if not running
15+
if ! pgrep -x "rserver" > /dev/null 2>&1; then
16+
sudo rstudio-server start
17+
fi
18+
19+
# Minimal R packages you might want – optional
20+
Rscript -e 'install.packages(c("quarto"), repos = "https://cloud.r-project.org")' || true

.devcontainer/welcome.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Source: Adapted from https://github.com/boettiger-lab/nasa-topst-env-justice (MIT)
2+
3+
#!/usr/bin/env bash
4+
set -euo pipefail
5+
6+
# Ensure RStudio is running (idempotent)
7+
if ! pgrep -x "rserver" > /dev/null 2>&1; then
8+
sudo rstudio-server start
9+
fi
10+
11+
cat <<'EOF'
12+
========================================
13+
Welcome to this R + Quarto Codespace
14+
========================================
15+
16+
RStudio Server is available at:
17+
18+
http://127.0.0.1:8787
19+
20+
In GitHub Codespaces:
21+
22+
- Open the "Ports" panel.
23+
- Find the "RStudio (8787)" port.
24+
- If it is not already open, choose "Open in browser".
25+
26+
Once RStudio is open, you can:
27+
- Open a .qmd file
28+
- Use the "Render" button or run:
29+
30+
quarto::quarto_preview()
31+
32+
to preview your document.
33+
========================================
34+
EOF

0 commit comments

Comments
 (0)