Skip to content

Commit e8487ae

Browse files
committed
Add a link into the video walkthrough
1 parent a7664b0 commit e8487ae

5 files changed

+141
-6
lines changed

R-shinylive-demo.qmd

+74-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ filters:
1010

1111
This document contains just the [Shiny App source code](https://github.com/jcheng5/posit-conf-2023-shinylive/blob/d385ad18eb0d867f25cc4721d9e8c25aeb2dfb90/slides.qmd#L299) used in Joe Cheng's [posit::conf(2023) demo](https://jcheng5.github.io/posit-conf-2023-shinylive/#/option-3-include-1) (Warning: Large file size, don't open on mobile!)
1212

13-
For a detailed breakdown, please see the <index.qmd> file.
13+
For a detailed breakdown, please see the [index.qmd](index.qmd) file.
1414

1515
```{shinylive-r}
1616
#| standalone: true
@@ -67,4 +67,76 @@ server <- function(input, output, session) {
6767
6868
# Create Shiny app ----
6969
shinyApp(ui = ui, server = server)
70-
```
70+
```
71+
72+
73+
Document Source (minus links):
74+
75+
````md
76+
---
77+
title: "Joe Cheng's r-shinylive App in a Quarto document!"
78+
format:
79+
html:
80+
resources:
81+
- shinylive-sw.js
82+
filters:
83+
- shinylive
84+
---
85+
86+
```{shinylive-r}
87+
#| standalone: true
88+
#| viewerHeight: 600
89+
library(shiny)
90+
library(bslib)
91+
92+
# Define UI for app that draws a histogram ----
93+
ui <- page_sidebar(
94+
sidebar = sidebar(open = "open",
95+
numericInput("n", "Sample count", 100),
96+
checkboxInput("pause", "Pause", FALSE),
97+
),
98+
plotOutput("plot", width=1100)
99+
)
100+
101+
server <- function(input, output, session) {
102+
data <- reactive({
103+
input$resample
104+
if (!isTRUE(input$pause)) {
105+
invalidateLater(1000)
106+
}
107+
rnorm(input$n)
108+
})
109+
110+
output$plot <- renderPlot({
111+
hist(data(),
112+
breaks = 40,
113+
xlim = c(-2, 2),
114+
ylim = c(0, 1),
115+
lty = "blank",
116+
xlab = "value",
117+
freq = FALSE,
118+
main = ""
119+
)
120+
121+
x <- seq(from = -2, to = 2, length.out = 500)
122+
y <- dnorm(x)
123+
lines(x, y, lwd=1.5)
124+
125+
lwd <- 5
126+
abline(v=0, col="red", lwd=lwd, lty=2)
127+
abline(v=mean(data()), col="blue", lwd=lwd, lty=1)
128+
129+
legend(legend = c("Normal", "Mean", "Sample mean"),
130+
col = c("black", "red", "blue"),
131+
lty = c(1, 2, 1),
132+
lwd = c(1, lwd, lwd),
133+
x = 1,
134+
y = 0.9
135+
)
136+
}, res=140)
137+
}
138+
139+
# Create Shiny app ----
140+
shinyApp(ui = ui, server = server)
141+
```
142+
````

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# r-shinylive-demo
22

3-
Interested in deploying a Shiny application for R within Quarto? This is the repository for you! Here's a summary of what you can find in the repository:
3+
Interested in deploying a serverless Shiny application for R within Quarto? This is the repository for you! Here's a summary of what you can find in the repository:
44

55
- **[index.qmd](index.qmd):** This file contains a tutorial that provides step-by-step instructions and guidance on using `r-shinylive` to embed Shiny applications in Quarto documents.
66

77
- **[R-shinylive-demo.qmd](R-shinylive-demo.qmd):** Inside this file, you can find a working example of the Shiny app that was used in Joe Cheng's [posit::conf(2023) demo](https://jcheng5.github.io/posit-conf-2023-shinylive/#/option-3-include-1). Please note that Joe's presentation contains files that are large in size and is not recommended for mobile devices. You can also refer to the [source code](https://github.com/jcheng5/posit-conf-2023-shinylive/blob/d385ad18eb0d867f25cc4721d9e8c25aeb2dfb90/slides.qmd#L299) of the demo.
88

99
- **[template-r-shinylive.qmd](template-r-shinylive.qmd):** This file provides a skeleton template that you can use to populate your own Shiny apps. It serves as a starting point for creating your interactive Quarto documents with Shiny applications. Please note that you will still need to install the required software as mentioned in the tutorial.
1010

11-
- **[_quarto.yml](_quarto.yml):** This configuration file is essential for Quarto and `shinylive` to work together effectively.
11+
- **[_quarto.yml](_quarto-default.yml):** This configuration file is essential for Quarto and `shinylive` to work together effectively.
1212

1313
- **[.github/workflows/publish-demo.yml](.github/workflows/publish-demo.yml):** This file contains a sample workflow configuration for creating a website that embeds R Shiny applications using GitHub Actions and deploys it to GitHub Pages.
1414

@@ -24,6 +24,14 @@ You can see the live version built from the repository here:
2424

2525
<https://coatless-quarto.github.io/r-shinylive-demo/>
2626

27+
## Video Tutorial
28+
29+
Prefer a hands-on visual guide? Check out the following YouTube video:
30+
31+
[![Creating a Serverless Shiny App using Quarto with R Shinylive](https://img.youtube.com/vi/6y2FnAugP8E/0.jpg)](https://www.youtube.com/watch?v=6y2FnAugP8E)
32+
33+
We'll go through every step and provide some commentary along the way!
34+
2735
# Using r-shinylive for Serverless Shiny Apps in Quarto Documents
2836

2937
Are you interested in creating your own Quarto document with embedded static Shiny apps? This tutorial will guide you through the process of using the `r-shinylive` R package to achieve just that. Let's get started!
@@ -49,14 +57,24 @@ quarto create project default
4957

5058
![Screenshot showing the Terminal tab of RStudio with the command to create a Quarto project.](images/create-quarto-r-shiny-live-project.png)
5159

52-
During project creation, you'll be prompted to provide a directory name. This name will also serve as the Quarto document filename. Please note that if you skip this step, a `_quarto.yml` file won't be generated, resulting in an error when you attempt to render the document.
60+
61+
While creating the project, you'll be prompted to specify a directory name. This name will also serve as the filename for your Quarto document. It's crucial to note that skipping this step will result in the absence of a `_quarto.yml` file, leading to an error when you attempt to render the document. The error message will resemble the following:
5362

5463
```md
5564
ERROR:
5665
The shinylive extension must be used in a Quarto project directory
5766
(with a _quarto.yml file).
5867
```
5968

69+
Ensure that the contents of the `_quarto.yml` file match the following structure:
70+
71+
```yaml
72+
project:
73+
title: "R-shinylive-demo"
74+
```
75+
76+
Here, the `title` field should contain the name of the Quarto file up to the extension.
77+
6078
## Installing the Quarto Extension for r-shinylive
6179

6280
**Step 3:** Install the Quarto extension for `shinylive`. In the Terminal tab, run the following command:

_quarto-default.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
title: "R-shinylive-demo"

index.qmd

+18-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ server <- function(input, output, session) {
7777
shinyApp(ui = ui, server = server)
7878
```
7979

80+
## Video Tutorial
81+
82+
Prefer a hands-on visual guide? Check out the following YouTube video:
83+
84+
[![Creating a Serverless Shiny App using Quarto with R Shinylive](https://img.youtube.com/vi/6y2FnAugP8E/0.jpg)](https://www.youtube.com/watch?v=6y2FnAugP8E)
85+
86+
We'll go through every step and provide some commentary along the way!
87+
8088
# Using r-shinylive for Serverless Shiny Apps in Quarto Documents
8189

8290
Are you interested in creating your own Quarto document with embedded static Shiny apps? This tutorial will guide you through the process of using the `r-shinylive` R package to achieve just that. Let's get started!
@@ -102,14 +110,23 @@ quarto create project default
102110

103111
![Screenshot showing the Terminal tab of RStudio with the command to create a Quarto project.](images/create-quarto-r-shiny-live-project.png)
104112

105-
During project creation, you'll be prompted to provide a directory name. This name will also serve as the Quarto document filename. Please note that if you skip this step, a `_quarto.yml` file won't be generated, resulting in an error when you attempt to render the document.
113+
While creating the project, you'll be prompted to specify a directory name. This name will also serve as the filename for your Quarto document. It's crucial to note that skipping this step will result in the absence of a `_quarto.yml` file, leading to an error when you attempt to render the document. The error message will resemble the following:
106114

107115
```md
108116
ERROR:
109117
The shinylive extension must be used in a Quarto project directory
110118
(with a _quarto.yml file).
111119
```
112120

121+
Ensure that the contents of the `_quarto.yml` file match the following structure:
122+
123+
```yaml
124+
project:
125+
title: "R-shinylive-demo"
126+
```
127+
128+
Here, the `title` field should contain the name of the Quarto file up to the extension.
129+
113130
## Installing the Quarto Extension for r-shinylive
114131

115132
**Step 3:** Install the Quarto extension for `shinylive`. In the Terminal tab, run the following command:

template-r-shinylive.qmd

+26
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,29 @@ server <- function(input, output, session) {
2323
2424
shinyApp(ui, server)
2525
```
26+
27+
Full Skeletal Document Source:
28+
29+
````md
30+
---
31+
title: "Template for r-shinylive Quarto document"
32+
format:
33+
html:
34+
resources:
35+
- shinylive-sw.js
36+
filters:
37+
- shinylive
38+
---
39+
40+
```{shinylive-r}
41+
#| standalone: true
42+
43+
ui <- ...
44+
45+
server <- function(input, output, session) {
46+
...
47+
}
48+
49+
shinyApp(ui, server)
50+
```
51+
````

0 commit comments

Comments
 (0)