Skip to content

Commit 31a3d3c

Browse files
committed
Streamline README
1 parent 498c930 commit 31a3d3c

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

.github/workflows/build-and-deploy-shinylive-r-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: r-lib/actions/setup-r-dependencies@v2
3434
with:
3535
packages:
36-
cran::shinylive@0.1.1
36+
cran::shinylive
3737

3838
# Export the current working directory as the shiny app
3939
# using the pinned version of the Shinylive R package

README.md

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
This repository demonstrates how to deploy an R Shinylive app using GitHub Actions and GitHub Pages.
44

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)
610

711
## Shinylive App Size
812

@@ -35,11 +39,15 @@ Adding more R packages through in-app dependencies will expand this list and inc
3539

3640
## Deploying Automatically with GitHub Actions
3741

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.
3945

4046
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).
4147

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:
4351

4452
```sh
4553
.
@@ -50,7 +58,11 @@ Specifically, we're advocating for a file structure of:
5058
└── app.R
5159
```
5260

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.
5466

5567
```yaml
5668
on:
@@ -84,15 +96,16 @@ jobs:
8496
uses: r-lib/actions/setup-r@v2
8597

8698
# Install and pin the shinylive R package dependency
99+
# to the current version on CRAN
87100
- name: "Setup R dependency for Shinylive App export"
88101
uses: r-lib/actions/setup-r-dependencies@v2
89102
with:
90103
packages:
91-
cran::shinylive@0.1.1
104+
cran::shinylive
92105

93106
# Export the current working directory as the shiny app
94107
# 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
96109
shell: Rscript {0}
97110
run: |
98111
shinylive::export(".", "_site")
@@ -113,30 +126,38 @@ jobs:
113126
uses: actions/deploy-pages@v2
114127
```
115128
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
135-
> [`upload-pages-artifact`](https://github.com/actions/upload-pages-artifact)
136-
> 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:
140161

141162
- Clicking on the repository's **Settings** page
142163
- Selecting **Pages** on the left sidebar.
@@ -145,19 +166,26 @@ Deployment through the GitHub Actions to GitHub Pages requires it to be enabled
145166

146167
[![Example annotation of the repository's Settings page for GitHub Actions deployment][1]][1]
147168

148-
149169
## Working Example
150170

151171
You can view the example shinylive-ified [app.R](app.R) source included in the repository here:
152172

153173
<https://tutorials.thecoatlessprofessor.com/convert-shiny-app-r-shinylive>
154174

155-
Some quick screenshots that describe whats up:
175+
Keep in mind that the exported app size is not mobile-friendly (approximately 66.8 MB).
176+
177+
If you are data constrained, you can see the app in this screenshot:
156178

157179
[![Example of the working shinylive app][2]][2]
158180

181+
Moreover, you can view one of the deployments app's commit size here:
182+
159183
[![Summary of the deployment of the shinylive app][3]][3]
160184

185+
# Fin
186+
187+
Huzzah! You've successfully learned how to deploy an R Shinylive app via GitHub Pages using GitHub Actions.
188+
Now, unleash your creativity and start building!
161189

162190
[1]: https://i.stack.imgur.com/kF2pf.jpg
163191
[2]: https://i.stack.imgur.com/DQ3Z1.jpg

0 commit comments

Comments
 (0)