Skip to content

Commit

Permalink
add rstudio bash script (#137)
Browse files Browse the repository at this point in the history
* add rstudio bash script

* Apply suggestions from code review

* Fix .Rprofile style

* Change the admiral default propagation branch to main

* Change the admiraldev default propagation branch to main

---------

Co-authored-by: pharmaverse-bot <[email protected]>
Co-authored-by: Adam Foryś <[email protected]>
3 people authored Sep 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 117d518 commit 25d9afb
Showing 8 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Set renv profile base on R version.
.get_dependencies <- function(project_dir) {

admdev_loc <- find.package("admiraldev", lib.loc = .libPaths(), quiet = TRUE)
adm_dev_suggests <- if(length(admdev_loc) != 0) {
adm_dev_suggests <- if (length(admdev_loc) != 0) {
renv:::renv_dependencies_discover_description(admdev_loc, fields = c("Depends", "Imports", "LinkingTo", "Suggests"))
} else {
data.frame(Packages = character(0))
2 changes: 1 addition & 1 deletion .devcontainer/4.1/devcontainer.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",
"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'",

"customizations": {
"vscode": {
2 changes: 1 addition & 1 deletion .devcontainer/4.2/devcontainer.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",
"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'",

"customizations": {
"vscode": {
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",
"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"; echo 'To open rstudio in your browser, just type rstudio in the terminal'",

"customizations": {
"vscode": {
6 changes: 6 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

# move script rstudio into /usr/bin
sudo cp "$(pwd)/.devcontainer/rstudio.sh" /usr/bin/rstudio
sudo chmod +x /usr/bin/rstudio

# Restore renv and install staged dependencies
R -q -e 'renv::restore(lockfile = file.path("renv", "profiles", paste(R.version$major, substr(R.version$minor, 1, 1), sep = "."), "renv.lock")); staged.dependencies::install_deps(staged.dependencies::dependency_table(project = ".", verbose = 1), verbose = 1);'

# Define rstudio default working directory
jq --arg folder "$(pwd)/" '. + { "initial_working_directory": $folder }' .devcontainer/rstudio-prefs.json > ~/.config/rstudio/rstudio-prefs.json
5 changes: 5 additions & 0 deletions .devcontainer/rstudio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

$BROWSER "https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"

exit 1
4 changes: 2 additions & 2 deletions .github/workflows/propagate.yml
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ jobs:
bundfussr
cicdguy
- name: admiraldev
target-branch: devel
target-branch: main
reviewers: |-
bms63
cicdguy
@@ -72,7 +72,7 @@ jobs:
reviewers: |-
cicdguy
- name: admiral
target-branch: devel
target-branch: main
reviewers: |-
cicdguy
bms63
12 changes: 6 additions & 6 deletions vignettes/docker_and_codespaces.Rmd
Original file line number Diff line number Diff line change
@@ -54,17 +54,17 @@ Note: Pressing directly `+` button will automatically create codespace for the l

#### Accessing Rstudio

To access Rstudio you need to go under vscode PORTS section :
To open rstudio in your browser, type `rstudio` on your current terminal. This script will wait until rstudio server is ready, and display the url in the terminal.

Known issue:

Sometimes ports are not automatically forwarded at the codespace creation. If you have some problems trying to access rstudio url, check the PORTS section on vscode :

```{r, echo = FALSE}
knitr::include_graphics("./assets/codespaces_rstudio_forward_port.png", dpi = 144)
```

Go on the row with port `8787` and open the url in a new browser.

Known issues:
- Sometimes ports are not automatically forwarded at the codespace creation. If you don't see `8787` port, then you need to manually add it (using "Add Port" button).
- The Rstudio server can takes some times to set-up after the codespace creation, so it might be not available right after the creation, and user might have to wait some minutes. We added a bash script `.devcontainer/codespaces_rstudio_status.sh` to check rstudio server status but it still an experimental feature.
If you don't see `8787` port, then you need to manually add it (using "Add Port" button).

### Usage limit / Pricing

0 comments on commit 25d9afb

Please sign in to comment.