-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
815 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: Render Quarto Files and Deploy to GitHub Pages | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: # Manual trigger | ||
|
||
jobs: | ||
render_quarto: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build Docker image | ||
run: | | ||
docker build -t demo-quarto-image . | ||
- name: Run Quarto in Docker container | ||
run: | | ||
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace my-quarto-image bash -c " | ||
echo 'Creating gallery directory...' | ||
mkdir -p gallery && \ | ||
echo 'gallery directory created.' | ||
FOLDERS=(python, R) | ||
echo 'Folders to process: ${FOLDERS[@]}' | ||
for FOLDER in \"\${FOLDERS[@]}\"; do | ||
echo 'Searching for .qmd and .ipynb files in $FOLDER...' | ||
find \"\$FOLDER\" \( -name '*.qmd' -o -name '*.ipynb' \) | while read file; do | ||
echo 'Processing file: $file' | ||
target_dir='gallery/$(dirname \"$file\")' | ||
echo 'Creating target directory: $target_dir' | ||
mkdir -p \"\$target_dir\" && echo 'Directory $target_dir created.' | ||
echo 'Attempting to render $file with execution...' | ||
if quarto render \"\$file\" --to html --output-dir \"\$target_dir\"; then | ||
echo 'Successfully rendered $file with execution.' | ||
else | ||
echo 'Failed to render $file with execution. Rendering without execution...' | ||
if quarto render \"\$file\" --to html --no-execute --output-dir \"\$target_dir\"; then | ||
echo 'Successfully rendered $file without execution.' | ||
else | ||
echo 'Rendering failed for $file, even without execution.' | ||
fi | ||
fi | ||
done | ||
done" | ||
- name: Generate Index HTML | ||
run: | | ||
echo "<html><body><h1>Gallery Index</h1><ul>" > gallery/index.html | ||
find gallery -name "*.html" | while read file; do | ||
file_name=$(basename "$file") | ||
echo "<li><a href=\"./$file\">$file_name</a></li>" >> gallery/index.html | ||
done | ||
echo "</ul></body></html>" >> gallery/index.html | ||
- name: Upload HTML output | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: gallery | ||
path: gallery | ||
|
||
- name: Set up Git user | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Commit and Push to docs branch | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
# Fetch all branches | ||
git fetch origin | ||
# Check if the docs branch exists, create it if not | ||
if git show-ref --quiet refs/heads/docs; then | ||
git checkout docs | ||
else | ||
git checkout --orphan docs | ||
fi | ||
# Copy the gallery folder to the root of the docs branch | ||
cp -r gallery/* . | ||
# Add, commit, and push changes | ||
git add gallery | ||
git commit -m "Update rendered Quarto files for GitHub Pages (commit: ${{ github.sha:0:7 }})" | ||
git push origin docs --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
## Before you start creating an example for others, please read the renv best-practices to make sure your code can be easily run and repro by others | ||
|
||
`renv` is a good practice to manage R package dependencies. Follow the steps below to restore the project environment, | ||
start working, add libraries as needed, and create a snapshot of the dependencies for version control. This will ensure that whoever checkout the code from this repo will be | ||
working with the same package versions as your original environment. | ||
|
||
### 1. Restore the Environment with `renv` | ||
|
||
To restore the R environment with the exact packages used in this project, use the `renv` lock file. | ||
This ensures that you are working with the same package versions as the original environment when it was created. | ||
|
||
1. Open R or RStudio within the project folder. | ||
2. Restore the environment by running: | ||
|
||
```r | ||
# Make sure you have the renv package installed | ||
install.packages("renv") | ||
|
||
# Restore the environment | ||
renv::restore() | ||
``` | ||
|
||
This will install all the required packages as installed as listed in the `renv.lock` file. | ||
|
||
### 2. Add Libraries as Needed | ||
|
||
As you work on the project, you might need to install additional R libraries. You can do this with `install.packages()` as usual. For example: | ||
|
||
```r | ||
install.packages("ggplot2") | ||
``` | ||
|
||
After installing new packages, be sure to update the environment snapshot to capture these new changes. | ||
|
||
### 3. Snapshot the Environment | ||
|
||
Once you have added or updated any packages, you need to create a new snapshot to update the `renv.lock` file. This ensures that any new dependencies are tracked. | ||
|
||
1. Create the snapshot with the following command in R: | ||
|
||
```r | ||
renv::snapshot() | ||
``` | ||
|
||
This will update the `renv.lock` file to reflect the current state of your project’s package library. | ||
|
||
2.Commit the changes to version control: | ||
|
||
```bash | ||
git add renv.lock | ||
git commit -m "Updated renv.lock after adding new libraries" | ||
git push origin <branch-name> | ||
``` | ||
|
||
This ensures that others working on the project can restore the environment with the new packages you added. | ||
|
||
### 4. Optional: Start a New `renv` Environment | ||
|
||
If you are starting a new project or want to reset the environment, you can initialize a new `renv` environment: | ||
|
||
```r | ||
# Initialize renv when there is no existing environment in the project | ||
renv::init() | ||
``` | ||
|
||
This will generate a new `renv` setup, including a fresh `renv.lock` file for you to manage the project’s dependencies. | ||
|
||
--- | ||
|
||
## 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). | ||
|
||
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 | ||
|
||
Since we use shinylive to showcase a shiny app in the quarto document, you 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: | ||
|
||
```bash | ||
quarto preview simple_example.qmd --port 4321 | ||
``` | ||
This will start a local server at port 4321 and open the document in your default browser. | ||
Any changes you make to the document will be automatically re-rendered in the browser. | ||
When you are satisfied with the document, you can render it to a standalone HTML file by running: | ||
|
||
```bash | ||
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. | ||
|
||
For more implementation details, please refer to the [Quarto documentation](https://quarto.org/). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
project: | ||
type: website | ||
output-dir: _site | ||
resources: | ||
- shinylive-sw.js | ||
|
||
website: | ||
title: "r-shinylive in Quarto" | ||
|
||
format: | ||
html: | ||
grid: | ||
body-width: 1350px | ||
sidebar-width: 200px | ||
margin-width: 200px | ||
toc: true |
Oops, something went wrong.