Skip to content

Commit

Permalink
add Qmd examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MeWu-IDM committed Sep 24, 2024
1 parent 0091bef commit 8bf3cb3
Show file tree
Hide file tree
Showing 12 changed files with 993 additions and 12 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// "source=${localWorkspaceFolder},target=/workspaces/${localWorkspaceFolder},type=bind,consistency=cached"
// ],
"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",
"postStartCommand:": "rstudio-server restart && jupyter lab --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token=''",
"portsAttributes": {
"8888": {
"label": "Jupyter Lab",
Expand Down
14 changes: 10 additions & 4 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ if [ -f "python/requirements.txt" ]; then
pip install -r python/requirements.txt
fi

# Set up renv for R
if [ -f "R/renv.lock" ]; then
cd R && R -e 'renv::restore()'
# Install R dependencies
if [ -f "R/install_packages.R" ]; then
Rscript R/install_packages.R
fi

# This may be done by the user
# Set up renv for R
#if [ -f "R/renv.lock" ]; then
# cd R && R -e 'renv::restore()'
#fi

# change the default working directory for RStudio
echo "session-default-working-dir=$localworkspace" >> /etc/rstudio/rsession.conf
echo "session-default-working-dir=$CODESPACE_VSCODE_FOLDER" >> /etc/rstudio/rsession.conf

rstudio-server start && jupyter lab --ip=0.0.0.0 --no-browser --allow-root --NotebookApp.token=''

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y \
libjpeg-dev \
libpng-dev \
libxt-dev \
libarchive-dev \
gdebi-core \
software-properties-common \
ffmpeg \
Expand Down
14 changes: 8 additions & 6 deletions r/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This ensures that you are working with the same package versions as the original
# Make sure you have the renv package installed
install.packages("renv")

# Restore the environment
# Restore the environment from the lock file
renv::restore()
```

Expand Down Expand Up @@ -71,20 +71,22 @@ This will generate a new `renv` setup, including a fresh `renv.lock` file for yo
## Use Quarto to Create Interactive Documents

In this folder we show an example that you can share code and ideas with others using a quarto document. See
[simple_example.qmd](./simple_example.qmd).
[simple_plot.qmd](./simple_plot/simple_plot.qmd).
[simple_example.qmd](./shinylive_demo/simple_example.qmd).


To begin with the example, you can open the `simple_example.qmd` file in Rstudio or other IDEs such as VS Code with the Quarto extension installed.

### 1.How to Run the Example
### How to Run the Example

Since we use shinylive to showcase a shiny app in the quarto document, you need to install the `shinylive` package first.
note: if you are running a shinylive that showcases a shiny app in the quarto document, you will need to install the `shinylive` package first.
This should already be included in the renv.lock file if you follow the above instructions.

```bash
quarto install extension quarto-ext/shinylive
```

Then you can preview and render the quarto document by running the following command in the terminal:
You can preview and render the quarto document by running the following command in the terminal:

```bash
quarto preview simple_example.qmd --port 4321
Expand All @@ -97,7 +99,7 @@ When you are satisfied with the document, you can render it to a standalone HTML
quarto render simple_example.qmd
```

This will use the `_quarto.yaml_` configuration file to render the document to an HTML file in the `output-dir` directory defined.
This will use the `_quarto.yaml_` configuration file or the yaml section in your quarto document to render the desired file format and save them in the `output-dir` directory defined.

For more implementation details, please refer to the [Quarto documentation](https://quarto.org/).

26 changes: 26 additions & 0 deletions r/install_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
options(Ncpus = parallel::detectCores())

if (.Platform$OS.type == "unix") {
type <- "source"
}else{
type <- "binary"
}


pkgnames <- c(
'devtools', 'DT',
'shiny', 'shinyjs', 'shinyalert', 'shinyWidgets', 'shinythemes', 'shinycssloaders', 'shinyBS', 'shinylive',
'dplyr','ggplot2', 'plotly', 'tidyr', 'stringr', 'logr', 'tidyverse',
'knitr', 'rmarkdown'
)

print(paste0("Install Packages from Cran : ", pkgnames))
install.packages(pkgnames,
repos='http://cran.rstudio.com/',
type=type)

# Make sure packages are available
if (length(pkgnames[which (!pkgnames %in% installed.packages()[,'Package'])]) >0 ){
cat(paste0("Package did not install correctly:", c(pkgnames[which (!pkgnames %in% installed.packages()[,'Package'])]), "\n"))
stop("some packages are not available, please investigate...")
}
File renamed without changes.
4 changes: 2 additions & 2 deletions r/renv.lock → r/shinylive_demo/renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@
},
"renv": {
"Package": "renv",
"Version": "1.0.7",
"Version": "1.0.9",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "397b7b2a265bc5a7a06852524dabae20"
"Hash": "ef233f0e9064fc88c898b340c9add5c2"
},
"rlang": {
"Package": "rlang",
Expand Down
13 changes: 13 additions & 0 deletions r/shinylive_demo/shinylive_demo.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
File renamed without changes.
Loading

0 comments on commit 8bf3cb3

Please sign in to comment.