From 8bf3cb3b64d87f3787a90c269a4854c042fef5d5 Mon Sep 17 00:00:00 2001 From: mewu Date: Tue, 24 Sep 2024 12:24:05 -0700 Subject: [PATCH] add Qmd examples --- .devcontainer/devcontainer.json | 1 + .devcontainer/postCreateCommand.sh | 14 +- Dockerfile | 1 + r/README.md | 14 +- r/install_packages.R | 26 + r/{ => shinylive_demo}/_quarto.yml | 0 r/{ => shinylive_demo}/renv.lock | 4 +- r/shinylive_demo/shinylive_demo.Rproj | 13 + r/{ => shinylive_demo}/simple_example.qmd | 0 r/simple_plot/renv.lock | 833 ++++++++++++++++++++++ r/simple_plot/simple_plot.Rproj | 13 + r/simple_plot/simple_plot.qmd | 86 +++ 12 files changed, 993 insertions(+), 12 deletions(-) create mode 100644 r/install_packages.R rename r/{ => shinylive_demo}/_quarto.yml (100%) rename r/{ => shinylive_demo}/renv.lock (98%) create mode 100644 r/shinylive_demo/shinylive_demo.Rproj rename r/{ => shinylive_demo}/simple_example.qmd (100%) create mode 100644 r/simple_plot/renv.lock create mode 100644 r/simple_plot/simple_plot.Rproj create mode 100644 r/simple_plot/simple_plot.qmd diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 3546dba..108685b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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", diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 61a5158..cee955a 100644 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -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='' diff --git a/Dockerfile b/Dockerfile index ac0ba45..857181a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ diff --git a/r/README.md b/r/README.md index 53b73e2..8b2833d 100644 --- a/r/README.md +++ b/r/README.md @@ -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() ``` @@ -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 @@ -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/). diff --git a/r/install_packages.R b/r/install_packages.R new file mode 100644 index 0000000..1741e78 --- /dev/null +++ b/r/install_packages.R @@ -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...") +} \ No newline at end of file diff --git a/r/_quarto.yml b/r/shinylive_demo/_quarto.yml similarity index 100% rename from r/_quarto.yml rename to r/shinylive_demo/_quarto.yml diff --git a/r/renv.lock b/r/shinylive_demo/renv.lock similarity index 98% rename from r/renv.lock rename to r/shinylive_demo/renv.lock index 4e8cfa5..cf98a03 100644 --- a/r/renv.lock +++ b/r/shinylive_demo/renv.lock @@ -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", diff --git a/r/shinylive_demo/shinylive_demo.Rproj b/r/shinylive_demo/shinylive_demo.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/r/shinylive_demo/shinylive_demo.Rproj @@ -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 diff --git a/r/simple_example.qmd b/r/shinylive_demo/simple_example.qmd similarity index 100% rename from r/simple_example.qmd rename to r/shinylive_demo/simple_example.qmd diff --git a/r/simple_plot/renv.lock b/r/simple_plot/renv.lock new file mode 100644 index 0000000..be84633 --- /dev/null +++ b/r/simple_plot/renv.lock @@ -0,0 +1,833 @@ +{ + "R": { + "Version": "4.4.0", + "Repositories": [ + { + "Name": "CRAN", + "URL": "https://packagemanager.posit.co/cran/latest" + } + ] + }, + "Packages": { + "MASS": { + "Package": "MASS", + "Version": "7.3-60.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats", + "utils" + ], + "Hash": "2f342c46163b0b54d7b64d1f798e2c78" + }, + "Matrix": { + "Package": "Matrix", + "Version": "1.7-0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "lattice", + "methods", + "stats", + "utils" + ], + "Hash": "1920b2f11133b12350024297d8a4ff4a" + }, + "R6": { + "Package": "R6", + "Version": "2.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "470851b6d5d0ac559e9d01bb352b4021" + }, + "RColorBrewer": { + "Package": "RColorBrewer", + "Version": "1.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "45f0398006e83a5b10b72a90663d8d8c" + }, + "Rcpp": { + "Package": "Rcpp", + "Version": "1.0.13", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods", + "utils" + ], + "Hash": "f27411eb6d9c3dada5edd444b8416675" + }, + "base64enc": { + "Package": "base64enc", + "Version": "0.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "543776ae6848fde2f48ff3816d0628bc" + }, + "bslib": { + "Package": "bslib", + "Version": "0.8.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "cachem", + "fastmap", + "grDevices", + "htmltools", + "jquerylib", + "jsonlite", + "lifecycle", + "memoise", + "mime", + "rlang", + "sass" + ], + "Hash": "b299c6741ca9746fb227debcb0f9fb6c" + }, + "cachem": { + "Package": "cachem", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "fastmap", + "rlang" + ], + "Hash": "cd9a672193789068eb5a2aad65a0dedf" + }, + "cli": { + "Package": "cli", + "Version": "3.6.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "b21916dd77a27642b447374a5d30ecf3" + }, + "colorspace": { + "Package": "colorspace", + "Version": "2.1-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "methods", + "stats" + ], + "Hash": "d954cb1c57e8d8b756165d7ba18aa55a" + }, + "crosstalk": { + "Package": "crosstalk", + "Version": "1.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R6", + "htmltools", + "jsonlite", + "lazyeval" + ], + "Hash": "ab12c7b080a57475248a30f4db6298c0" + }, + "digest": { + "Package": "digest", + "Version": "0.6.37", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "33698c4b3127fc9f506654607fb73676" + }, + "evaluate": { + "Package": "evaluate", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "6b567375113ceb7d9f800de4dd42218e" + }, + "fansi": { + "Package": "fansi", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "utils" + ], + "Hash": "962174cf2aeb5b9eea581522286a911f" + }, + "farver": { + "Package": "farver", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "680887028577f3fa2a81e410ed0d6e42" + }, + "fastmap": { + "Package": "fastmap", + "Version": "1.2.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "aa5e1cd11c2d15497494c5292d7ffcc8" + }, + "fontawesome": { + "Package": "fontawesome", + "Version": "0.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools", + "rlang" + ], + "Hash": "c2efdd5f0bcd1ea861c2d4e2a883a67d" + }, + "fs": { + "Package": "fs", + "Version": "1.6.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "15aeb8c27f5ea5161f9f6a641fafd93a" + }, + "ggplot2": { + "Package": "ggplot2", + "Version": "3.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "MASS", + "R", + "cli", + "glue", + "grDevices", + "grid", + "gtable", + "isoband", + "lifecycle", + "mgcv", + "rlang", + "scales", + "stats", + "tibble", + "vctrs", + "withr" + ], + "Hash": "44c6a2f8202d5b7e878ea274b1092426" + }, + "glue": { + "Package": "glue", + "Version": "1.7.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "methods" + ], + "Hash": "e0b3a53876554bd45879e596cdb10a52" + }, + "gtable": { + "Package": "gtable", + "Version": "0.3.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "grid", + "lifecycle", + "rlang" + ], + "Hash": "e18861963cbc65a27736e02b3cd3c4a0" + }, + "highr": { + "Package": "highr", + "Version": "0.11", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "xfun" + ], + "Hash": "d65ba49117ca223614f71b60d85b8ab7" + }, + "htmltools": { + "Package": "htmltools", + "Version": "0.5.8.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "base64enc", + "digest", + "fastmap", + "grDevices", + "rlang", + "utils" + ], + "Hash": "81d371a9cc60640e74e4ab6ac46dcedc" + }, + "htmlwidgets": { + "Package": "htmlwidgets", + "Version": "1.6.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grDevices", + "htmltools", + "jsonlite", + "knitr", + "rmarkdown", + "yaml" + ], + "Hash": "04291cc45198225444a397606810ac37" + }, + "isoband": { + "Package": "isoband", + "Version": "0.2.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "grid", + "utils" + ], + "Hash": "0080607b4a1a7b28979aecef976d8bc2" + }, + "jquerylib": { + "Package": "jquerylib", + "Version": "0.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "htmltools" + ], + "Hash": "5aab57a3bd297eee1c1d862735972182" + }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.8.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "methods" + ], + "Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b" + }, + "knitr": { + "Package": "knitr", + "Version": "1.48", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "evaluate", + "highr", + "methods", + "tools", + "xfun", + "yaml" + ], + "Hash": "acf380f300c721da9fde7df115a5f86f" + }, + "labeling": { + "Package": "labeling", + "Version": "0.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "graphics", + "stats" + ], + "Hash": "b64ec208ac5bc1852b285f665d6368b3" + }, + "lattice": { + "Package": "lattice", + "Version": "0.22-6", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "stats", + "utils" + ], + "Hash": "cc5ac1ba4c238c7ca9fa6a87ca11a7e2" + }, + "lazyeval": { + "Package": "lazyeval", + "Version": "0.2.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "d908914ae53b04d4c0c0fd72ecc35370" + }, + "leaflet": { + "Package": "leaflet", + "Version": "2.2.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "RColorBrewer", + "crosstalk", + "htmltools", + "htmlwidgets", + "jquerylib", + "leaflet.providers", + "magrittr", + "methods", + "png", + "raster", + "scales", + "sp", + "stats", + "viridisLite", + "xfun" + ], + "Hash": "ca012d4a706e21ce217ba15f22d402b2" + }, + "leaflet.extras": { + "Package": "leaflet.extras", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools", + "htmlwidgets", + "leaflet", + "magrittr", + "stringr" + ], + "Hash": "1626fb22ec9e788f66c1d08fd863da4c" + }, + "leaflet.providers": { + "Package": "leaflet.providers", + "Version": "2.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "htmltools" + ], + "Hash": "c0b81ad9d5d932772f7a457ac398cf36" + }, + "lifecycle": { + "Package": "lifecycle", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "rlang" + ], + "Hash": "b8552d117e1b808b09a832f589b79035" + }, + "magrittr": { + "Package": "magrittr", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "7ce2733a9826b3aeb1775d56fd305472" + }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "cachem", + "rlang" + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, + "mgcv": { + "Package": "mgcv", + "Version": "1.9-1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "Matrix", + "R", + "graphics", + "methods", + "nlme", + "splines", + "stats", + "utils" + ], + "Hash": "110ee9d83b496279960e162ac97764ce" + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "tools" + ], + "Hash": "18e9c28c1d3ca1560ce30658b22ce104" + }, + "munsell": { + "Package": "munsell", + "Version": "0.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "colorspace", + "methods" + ], + "Hash": "4fd8900853b746af55b81fda99da7695" + }, + "nlme": { + "Package": "nlme", + "Version": "3.1-164", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "graphics", + "lattice", + "stats", + "utils" + ], + "Hash": "a623a2239e642806158bc4dc3f51565d" + }, + "pillar": { + "Package": "pillar", + "Version": "1.9.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "cli", + "fansi", + "glue", + "lifecycle", + "rlang", + "utf8", + "utils", + "vctrs" + ], + "Hash": "15da5a8412f317beeee6175fbc76f4bb" + }, + "pkgconfig": { + "Package": "pkgconfig", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "01f28d4278f15c76cddbea05899c5d6f" + }, + "png": { + "Package": "png", + "Version": "0.1-8", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "bd54ba8a0a5faded999a7aab6e46b374" + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" + }, + "raster": { + "Package": "raster", + "Version": "3.6-26", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp", + "methods", + "sp", + "terra" + ], + "Hash": "7d6eda494f34a644420ac1bfd2a8023a" + }, + "renv": { + "Package": "renv", + "Version": "1.0.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "ef233f0e9064fc88c898b340c9add5c2" + }, + "rlang": { + "Package": "rlang", + "Version": "1.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "utils" + ], + "Hash": "3eec01f8b1dee337674b2e34ab1f9bc1" + }, + "rmarkdown": { + "Package": "rmarkdown", + "Version": "2.28", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "bslib", + "evaluate", + "fontawesome", + "htmltools", + "jquerylib", + "jsonlite", + "knitr", + "methods", + "tinytex", + "tools", + "utils", + "xfun", + "yaml" + ], + "Hash": "062470668513dcda416927085ee9bdc7" + }, + "sass": { + "Package": "sass", + "Version": "0.4.9", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R6", + "fs", + "htmltools", + "rappdirs", + "rlang" + ], + "Hash": "d53dbfddf695303ea4ad66f86e99b95d" + }, + "scales": { + "Package": "scales", + "Version": "1.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "R6", + "RColorBrewer", + "cli", + "farver", + "glue", + "labeling", + "lifecycle", + "munsell", + "rlang", + "viridisLite" + ], + "Hash": "c19df082ba346b0ffa6f833e92de34d1" + }, + "sp": { + "Package": "sp", + "Version": "2.1-4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics", + "grid", + "lattice", + "methods", + "stats", + "utils" + ], + "Hash": "75940133cca2e339afce15a586f85b11" + }, + "stringi": { + "Package": "stringi", + "Version": "1.8.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "stats", + "tools", + "utils" + ], + "Hash": "39e1144fd75428983dc3f63aa53dfa91" + }, + "stringr": { + "Package": "stringr", + "Version": "1.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "magrittr", + "rlang", + "stringi", + "vctrs" + ], + "Hash": "960e2ae9e09656611e0b8214ad543207" + }, + "terra": { + "Package": "terra", + "Version": "1.7-78", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "Rcpp", + "methods" + ], + "Hash": "8f020def0792119cb98bd8f696dab22d" + }, + "tibble": { + "Package": "tibble", + "Version": "3.2.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "fansi", + "lifecycle", + "magrittr", + "methods", + "pillar", + "pkgconfig", + "rlang", + "utils", + "vctrs" + ], + "Hash": "a84e2cc86d07289b3b6f5069df7a004c" + }, + "tinytex": { + "Package": "tinytex", + "Version": "0.53", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "xfun" + ], + "Hash": "9db859e8aabbb474293dde3097839420" + }, + "utf8": { + "Package": "utf8", + "Version": "1.2.4", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "62b65c52671e6665f803ff02954446e9" + }, + "vctrs": { + "Package": "vctrs", + "Version": "0.6.5", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "cli", + "glue", + "lifecycle", + "rlang" + ], + "Hash": "c03fa420630029418f7e6da3667aac4a" + }, + "viridisLite": { + "Package": "viridisLite", + "Version": "0.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R" + ], + "Hash": "c826c7c4241b6fc89ff55aaea3fa7491" + }, + "withr": { + "Package": "withr", + "Version": "3.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "graphics" + ], + "Hash": "07909200e8bbe90426fbfeb73e1e27aa" + }, + "xfun": { + "Package": "xfun", + "Version": "0.47", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "R", + "grDevices", + "stats", + "tools" + ], + "Hash": "36ab21660e2d095fef0d83f689e0477c" + }, + "yaml": { + "Package": "yaml", + "Version": "2.3.10", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "51dab85c6c98e50a18d7551e9d49f76c" + } + } +} diff --git a/r/simple_plot/simple_plot.Rproj b/r/simple_plot/simple_plot.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/r/simple_plot/simple_plot.Rproj @@ -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 diff --git a/r/simple_plot/simple_plot.qmd b/r/simple_plot/simple_plot.qmd new file mode 100644 index 0000000..69ab255 --- /dev/null +++ b/r/simple_plot/simple_plot.qmd @@ -0,0 +1,86 @@ +--- +title: "Simple R Example" +date: "2024-09-23" +output: html +execute: + echo: true +--- + +# This is a very basic quarto document for sharing your code + + +This is a simple example of how to create a bar plot in R using ggplot2. + + +```{r} +# Load necessary library +library(ggplot2) + +# Create a simple dataset +data <- data.frame( + category = c("A", "B", "C", "D"), + values = c(3, 7, 9, 4) +) + +# Create a bar plot +ggplot(data, aes(x = category, y = values)) + + geom_bar(stat = "identity", fill = "steelblue") + + theme_minimal() + + labs(title = "Simple Bar Plot", x = "Category", y = "Values") +``` + +::: {.callout-note} +You can create a callout note by using the `callout-note` class. +::: + +Show some data your map + +```{r} +# Load required packages +library(leaflet) +library(leaflet.extras) # Provides heatmap functionality + +# Define the latitude and longitude for Seattle, WA +seattle_coords <- c(47.6062, -122.3321) + +# Generate some sample data around the Seattle area +set.seed(123) # for reproducibility +lat <- rnorm(100, mean = 47.6062, sd = 0.01) # latitude around Seattle +lng <- rnorm(100, mean = -122.3321, sd = 0.01) # longitude around Seattle +intensity <- rnorm(100, mean = 1, sd = 0.5) # sample intensity values + +# Create a data frame for heatmap +heatmap_data <- data.frame(lat, lng, intensity) + +# Create the Leaflet map +leaflet() %>% + addTiles() %>% # Add default OpenStreetMap tiles + setView(lng = seattle_coords[2], lat = seattle_coords[1], zoom = 12) %>% + addHeatmap( + lng = heatmap_data$lng, + lat = heatmap_data$lat, + intensity = heatmap_data$intensity, + blur = 20, max = 1, radius = 15 + ) +``` + + +::: {.callout-tip} +You can create callout-tips! Just use the `callout-tip` class. +::: + + +Quarto supports LaTeX-style math for rendering mathematical equations in documents. This type of math can be used to display both inline math expressions and block (display) math expressions. For example, the equation $E=mc^2$ is an example of inline math, while the equation $$ A = \pi r^2 $$ is the example of block math. + + +You can use mermaid to create diagrams in your documents. For example, the following code creates a simple flowchart: +```{mermaid} +graph TD; + A[Start] --> B[Step 1]; + B --> C[Step 2]; + C --> D[End]; + +``` + +If you want to learn more, check this video: +{{< video https://youtu.be/_f3latmOhew?si=HE6bpTObWfmnAZzM >}}