You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-32Lines changed: 60 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,11 @@
2
2
3
3
This repository demonstrates how to deploy an R Shinylive app using GitHub Actions and GitHub Pages.
4
4
5
-
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 [Faustin Gashakamba](https://stackoverflow.com/users/5618354/faustin-gashakamba).
5
+
If you're interested in a Python version, you can find it: [here](https://github.com/coatless-tutorials/convert-py-shiny-app-to-py-shinylive-app).
6
+
7
+
## Background
8
+
9
+
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 [Faustin Gashakamba](https://stackoverflow.com/users/5618354/faustin-gashakamba)
6
10
7
11
## Shinylive App Size
8
12
@@ -35,11 +39,15 @@ Adding more R packages through in-app dependencies will expand this list and inc
35
39
36
40
## Deploying Automatically with GitHub Actions
37
41
38
-
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.
42
+
### Serving a Website from a GitHub Repository
43
+
44
+
One of the standard approaches when working with web deployment is to use 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). However, this approach is problematic for sharing the app on GitHub pages since you can quickly bloat the size of the repository with binary data, which impacts being able to quickly clone the repository and decreases the working efficiency.
39
45
40
46
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).
41
47
42
-
Specifically, we're advocating for a file structure of:
48
+
### Project Layout
49
+
50
+
For this to work, we're advocating for a repository structure of:
43
51
44
52
```sh
45
53
.
@@ -50,7 +58,11 @@ Specifically, we're advocating for a file structure of:
50
58
└── app.R
51
59
```
52
60
53
-
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:
61
+
The source for the R Shiny app can be placed into the [`app.R`](app.R) file 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.
62
+
63
+
## GitHub Action Workflow for Converting and Deploying
64
+
65
+
The following workflow contains a single step that encompasses both the build and deploy phases. For more details about customizing the conversion step or the deployment step, please see the two notes that immediately follow from the workflow.
54
66
55
67
```yaml
56
68
on:
@@ -84,15 +96,16 @@ jobs:
84
96
uses: r-lib/actions/setup-r@v2
85
97
86
98
# Install and pin the shinylive R package dependency
99
+
# to the current version on CRAN
87
100
- name: "Setup R dependency for Shinylive App export"
88
101
uses: r-lib/actions/setup-r-dependencies@v2
89
102
with:
90
103
packages:
91
-
cran::shinylive@0.1.1
104
+
cran::shinylive
92
105
93
106
# Export the current working directory as the shiny app
94
107
# using the pinned version of the Shinylive R package
95
-
- name: Create Shinylive App from working directory files
108
+
- name: Create R Shinylive App from working directory files
96
109
shell: Rscript {0}
97
110
run: |
98
111
shinylive::export(".", "_site")
@@ -113,30 +126,38 @@ jobs:
113
126
uses: actions/deploy-pages@v2
114
127
```
115
128
116
-
> [!NOTE]
117
-
>
118
-
> We make an assumption when exporting the Shiny app about:
119
-
>
120
-
> 1. the app can be found in the working directory, e.g. `.`
121
-
> 2. the deployment folder is `_site`
122
-
>
123
-
> If this is not the case, please modified the step in the deployment recipe
124
-
> that contains:
125
-
>
126
-
> ```r
127
-
> shinylive::export(".", "_site")
128
-
> ```
129
-
>
130
-
131
-
> [!NOTE]
132
-
>
133
-
> The output directory of `_site` for the converted shinylive app
134
-
> is used since it is the default path location for the
> action. This can be changed by supplying `path` parameter under `with` in the
137
-
> "Upload Pages artifact" step.
138
-
139
-
Deployment through the GitHub Actions to GitHub Pages requires it to be enabled on the repository by:
129
+
130
+
#### Conversion Assumptions
131
+
132
+
When exporting the R Shiny app, we assume:
133
+
134
+
1. The app is located in the working directory, denoted by `.`.
135
+
2. The deployment folder or what should be shown on the web is `_site`.
136
+
137
+
If these assumptions don't align with your setup, please modify the conversion step accordingly.
138
+
139
+
```yaml
140
+
- name: Create R Shinylive App from working directory files
141
+
shell: Rscript {0}
142
+
run: |
143
+
shinylive::export(".", "_site")
144
+
```
145
+
146
+
#### Customize Deployment Path
147
+
148
+
The output directory `_site` for the converted Shinylive app is used as it's the default path for the [`upload-pages-artifact`](https://github.com/actions/upload-pages-artifact) action. You can change this by supplying a `path` parameter under `with` in the "Upload Pages artifact" step, e.g.
149
+
150
+
```yaml
151
+
- name: Upload Pages artifact
152
+
uses: actions/upload-pages-artifact@v2
153
+
with:
154
+
retention-days: 1
155
+
path: "new-path-here"
156
+
```
157
+
158
+
## Enabling GitHub Pages Deployment
159
+
160
+
To enable deployment through GitHub Actions to GitHub Pages, please enable it on the repository by:
140
161
141
162
- Clicking on the repository's **Settings** page
142
163
- Selecting **Pages** on the left sidebar.
@@ -145,19 +166,26 @@ Deployment through the GitHub Actions to GitHub Pages requires it to be enabled
145
166
146
167
[![Example annotation of the repository's Settings page for GitHub Actions deployment][1]][1]
147
168
148
-
149
169
## Working Example
150
170
151
171
You can view the example shinylive-ified [app.R](app.R) source included in the repository here:
0 commit comments