Skip to content

Commit b14412b

Browse files
committed
Update README describing the deploy approach
1 parent 06663aa commit b14412b

File tree

1 file changed

+126
-2
lines changed

1 file changed

+126
-2
lines changed

README.md

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,131 @@ This repository demonstrates how to deploy an R Shinylive app using GitHub Actio
44

55
The initial app source code is from a [StackOverflow Question](https://stackoverflow.com/questions/78160039/using-shinylive-to-allow-deployment-of-r-shiny-apps-from-a-static-webserver-yiel) by [Dasha Semochkina](https://stackoverflow.com/users/23593955/dasha-semochkina).
66

7-
## Setup
87

9-
...
8+
## Shinylive App Size
109

10+
Shinylive apps require around 60 MB or more data due to their dependency on the initial webR base and all {shiny} package dependencies. When moving away from a compute server running Shiny Server to a generic web server, the trade-off lies in the amount of user bandwidth required. So, the users internet and computer is paying for the ability to view the app compared to the old status quo where the host paid a license fee (to Posit), server and maintenance costs.
11+
12+
You can inspect the current list of package dependencies for a basic Shiny app using the following R code:
13+
14+
15+
```r
16+
pkg_db <- tools::CRAN_package_db()
17+
shiny_pkg_dependencies <- tools::package_dependencies(
18+
packages = c("shiny"),
19+
recursive = TRUE,
20+
db = pkg_db
21+
)
22+
23+
shiny_pkg_dependencies
24+
#> $shiny
25+
#> [1] "methods" "utils" "grDevices" "httpuv" "mime"
26+
#> [6] "jsonlite" "xtable" "fontawesome" "htmltools" "R6"
27+
#> [11] "sourcetools" "later" "promises" "tools" "crayon"
28+
#> [16] "rlang" "fastmap" "withr" "commonmark" "glue"
29+
#> [21] "bslib" "cachem" "ellipsis" "lifecycle" "base64enc"
30+
#> [26] "jquerylib" "memoise" "sass" "digest" "Rcpp"
31+
#> [31] "cli" "magrittr" "stats" "graphics" "fs"
32+
#> [36] "rappdirs"
33+
```
34+
35+
Adding more R packages through in-app dependencies will expand this list and increase the download size of each app.
36+
37+
38+
## Deploying Automatically with GitHub Actions
39+
40+
Please **avoid** using the [`gh-pages` branch deployment technique](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-from-a-branch) for sharing the app on GitHub pages.
41+
42+
Instead, opt for the [GitHub Actions approach](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow), which is preferred because it doesn't store artifacts from converting a Shiny App into a Shinylive App inside the repository. Plus, this approach allows for Shinylive apps to be deployed up to the [GitHub Pages maximum of about 1 GB](https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#usage-limits).
43+
44+
Specifically, we're advocating for a file structure of:
45+
46+
```sh
47+
.
48+
├── .github
49+
│ └── workflows
50+
│ └── build-and-deploy-shinylive-r-app.yml
51+
├── README.md
52+
└── app.R
53+
```
54+
55+
Thus, we could place the example app source code into `app.R` and, then, use the following GitHub Action in `.github/workflows/build-and-deploy-shinylive-r-app.yml` to build and deploy the shinylive app every time the repository is updated:
56+
57+
```yaml
58+
on:
59+
push:
60+
branches: [main, master]
61+
release:
62+
types: [published]
63+
workflow_dispatch: {}
64+
65+
name: demo-r-shinylive-app
66+
67+
jobs:
68+
demo-website:
69+
runs-on: ubuntu-latest
70+
# Only restrict concurrency for non-PR jobs
71+
concurrency:
72+
group: r-shinylive-website-${{ github.event_name != 'pull_request' || github.run_id }}
73+
# Describe the permissions for obtain repository contents and
74+
# deploying a GitHub pages website for the repository
75+
permissions:
76+
contents: read
77+
pages: write
78+
id-token: write
79+
steps:
80+
# Obtain the contents of the repository
81+
- name: "Check out repository"
82+
uses: actions/checkout@v4
83+
84+
# Install R on the GitHub Actions worker
85+
- name: "Setup R"
86+
uses: r-lib/actions/setup-r@v2
87+
88+
# Install and pin the shinylive R package dependency
89+
- name: "Setup R dependency for Shinylive App export"
90+
uses: r-lib/actions/setup-r-dependencies@v2
91+
with:
92+
packages:
93+
cran::shinylive@0.1.1
94+
95+
# Export the current working directory as the shiny app
96+
# using the pinned version of the Shinylive R package
97+
- name: Create Shinylive App from working directory files
98+
shell: Rscript {0}
99+
run: |
100+
shinylive::export(".", "_site")
101+
102+
# Upload a tar file that will work with GitHub Pages
103+
# Make sure to set a retention day to avoid running into a cap
104+
# This artifact shouldn't be required after deployment onto pages was a success.
105+
- name: Upload Pages artifact
106+
uses: actions/upload-pages-artifact@v2
107+
with:
108+
retention-days: 1
109+
110+
# Use an Action deploy to push the artifact onto GitHub Pages
111+
# This requires the `Action` tab being structured to allow for deployment
112+
# instead of using `docs/` or the `gh-pages` branch of the repository
113+
- name: Deploy to GitHub Pages
114+
id: deployment
115+
uses: actions/deploy-pages@v2
116+
```
117+
118+
119+
## Working Example
120+
121+
For a comprehensive example demonstrating deployment, documentation, and a functional version of your app, refer to the following:
122+
123+
- Repository: https://github.com/coatless-tutorials/convert-shiny-app-r-shinylive
124+
- Deployed shiny app: https://tutorials.thecoatlessprofessor.com/convert-shiny-app-r-shinylive/
125+
126+
Some quick screenshots that describe whats up:
127+
128+
[![Example of the working shinylive app][1]][1]
129+
130+
[![Summary of the deployment of the shinylive app][2]][2]
131+
132+
133+
[1]: https://i.stack.imgur.com/DQ3Z1.jpg
134+
[2]: https://i.stack.imgur.com/Gzzy8.jpg

0 commit comments

Comments
 (0)