Skip to content

Commit bfdf840

Browse files
committed
Update the README with new features
1 parent 39c4971 commit bfdf840

File tree

2 files changed

+115
-27
lines changed

2 files changed

+115
-27
lines changed

README.Rmd

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,57 @@ package documentation more engaging and allows users to experiment with examples
126126
without installing R locally.
127127

128128
For this to work with developmental versions of your package, you will need to
129+
either have an account with [r-universe.dev](https://r-universe.dev/) or
129130
use the following `pkgdown` + `rwasm` build action:
130131

131132
<https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml>
132133

133134
For a fast setup, please use:
134135

135136
```r
136-
usethis::use_github_action("https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml")
137+
usethis::use_github_action(repos = "https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml")
137138
```
138139

139140
> [!IMPORTANT]
140141
>
141142
> Please make sure to delete your old `pkgdown.yml` file.
142143
144+
## Requirements
145+
146+
For `@examplesWebR` functionality, your package's `DESCRIPTION` file must
147+
have:
148+
149+
```
150+
Suggests:
151+
rocleteer
152+
Remotes: coatless-rpkg/rocleteer
153+
154+
Roxygen: list(..., packages = c("rocleteer"))
155+
156+
Config/rocleteer/webr-repo: https://user.github.io/pkgname/
157+
```
158+
159+
For the package to be usable in webR examples, you must
160+
specify a webR-compatible repository in your `DESCRIPTION` file. This
161+
repository can be generated by [`r-universe`](https://r-universe.dev/) or
162+
by using the above GitHub Action to build and serve a webR R binary alongside
163+
your pkgdown site.
164+
165+
By default, the `@examplesWebR` tag will look for the following:
166+
167+
- `Config/rocleteer/webr-repo: https://user.r-universe.dev/` (recommended)
168+
- `Config/rocleteer/webr-repo: https://user.github.io/pkgname/`
169+
- `URL` field containing GitHub Pages or R-universe patterns (shown above)
170+
171+
If none of these are found, the tag will produce a warning during processing
172+
and will not generate the webR section in the Rd file.
173+
174+
#### WebR Version Support
175+
176+
Only webR versions v0.5.4 and higher are supported.
177+
The tag will validate the version parameter and produce an error if an
178+
unsupported version is specified.
179+
143180
#### Generated Structure
144181

145182
When you use `@examplesWebR`, it generates:
@@ -165,7 +202,8 @@ it generates:
165202
\section{WebR}{
166203
\ifelse{html}{
167204
\out{
168-
<a href="webR_URL">\U0001F310 View in webR REPL</a>
205+
<button>\U0001F310 Try it in your browser!</button>
206+
<iframe href="webR_URL"></iframe>
169207
}
170208
}{
171209
\ifelse{latex}{
@@ -188,22 +226,23 @@ plot(x, y, type = "b", main = "Interactive Example")
188226
This creates:
189227

190228
- Regular examples with your R code
191-
- A "WebR" section with a "View in webR REPL" button in HTML documentation
192-
or a URL in LaTeX documentation.
193-
- The button opens the code in an interactive webR session
229+
- A "WebR" section with a "Try it in your browser" and "Open in Tab" buttons
230+
in HTML documentation or a URL in LaTeX documentation.
231+
- The button opens either an embedded webR session or
232+
a new tab with the code in an interactive webR REPL.
194233

195234
> [!NOTE]
196235
>
197236
> The `@examplesWebR` tag uses a simplified encoding scheme compatible with webR.
198237
199-
#### Embedded Mode
238+
#### Standalone Mode
200239

201-
For a more integrated experience, embed the webR REPL directly into the Rd
202-
file with:
240+
To avoid embedding the webR REPL, you can use the `@examplesWebR embed=false` tag.
241+
This will generate a link to the webR REPL without embedding it directly in the documentation.
203242

204243
```r
205244
#' @examplesWebR embed
206-
#' # This code will be available in an embedded webR session
245+
#' # This code will be available in a new web browser tab with the webR REPL
207246
#' library(ggplot2)
208247
#' ggplot(mtcars, aes(mpg, wt)) +
209248
#' geom_point() +
@@ -214,15 +253,18 @@ file with:
214253

215254
You can customize the `@examplesWebR` tag with additional options:
216255

217-
- `embed`: Embed an iframe instead of showing a link
218-
- `height=N`: Set iframe height in pixels (default: `300`)
256+
- `autorun`: Embed an iframe instead of showing a link (default: `"false"`)
257+
- `embed`: Embed an iframe instead of showing a link (default: `"true"`)
258+
- `height=N`: Set iframe height in pixels (default: `400`)
219259
- `version=X`: Specify webR version (default: `"latest"`)
260+
- `mode=X-Y`: Configure embedded webR interface (editor, plot, terminal, files) (default: `"editor-plot-terminal"`)
261+
- `channel=X`: Set webR communication channel (default: `"Automatic`)
220262

221263
For example, to embed with a specific height and version:
222264

223265
```r
224-
#' @examplesWebR embed height=500 version=v0.3.3
225-
#' # Custom height iframe with specific webR version
266+
#' @examplesWebR autorun height=500 version=v0.5.4
267+
#' # Custom height iframe with specific webR version that autoruns code
226268
#' summary(cars)
227269
#' plot(cars)
228270
```

README.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,58 @@ documentation more engaging and allows users to experiment with examples
119119
without installing R locally.
120120

121121
For this to work with developmental versions of your package, you will
122-
need to use the following `pkgdown` + `rwasm` build action:
122+
need to either have an account with
123+
[r-universe.dev](https://r-universe.dev/) or use the following
124+
`pkgdown` + `rwasm` build action:
123125

124126
<https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml>
125127

126128
For a fast setup, please use:
127129

128130
``` r
129-
usethis::use_github_action("https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml")
131+
usethis::use_github_action(repos = "https://github.com/r-wasm/actions/blob/main/examples/rwasm-binary-and-pkgdown-site.yml")
130132
```
131133

132134
> \[!IMPORTANT\]
133135
>
134136
> Please make sure to delete your old `pkgdown.yml` file.
135137
138+
## Requirements
139+
140+
For `@examplesWebR` functionality, your package’s `DESCRIPTION` file
141+
must have:
142+
143+
Suggests:
144+
rocleteer
145+
Remotes: coatless-rpkg/rocleteer
146+
147+
Roxygen: list(..., packages = c("rocleteer"))
148+
149+
Config/rocleteer/webr-repo: https://user.github.io/pkgname/
150+
151+
For the package to be usable in webR examples, you must specify a
152+
webR-compatible repository in your `DESCRIPTION` file. This repository
153+
can be generated by [`r-universe`](https://r-universe.dev/) or by using
154+
the above GitHub Action to build and serve a webR R binary alongside
155+
your pkgdown site.
156+
157+
By default, the `@examplesWebR` tag will look for the following:
158+
159+
- `Config/rocleteer/webr-repo: https://user.r-universe.dev/`
160+
(recommended)
161+
- `Config/rocleteer/webr-repo: https://user.github.io/pkgname/`
162+
- `URL` field containing GitHub Pages or R-universe patterns (shown
163+
above)
164+
165+
If none of these are found, the tag will produce a warning during
166+
processing and will not generate the webR section in the Rd file.
167+
168+
#### WebR Version Support
169+
170+
Only webR versions v0.5.4 and higher are supported. The tag will
171+
validate the version parameter and produce an error if an unsupported
172+
version is specified.
173+
136174
#### Generated Structure
137175

138176
When you use `@examplesWebR`, it generates:
@@ -158,7 +196,8 @@ it generates:
158196
\section{WebR}{
159197
\ifelse{html}{
160198
\out{
161-
<a href="webR_URL">\U0001F310 View in webR REPL</a>
199+
<button>\U0001F310 Try it in your browser!</button>
200+
<iframe href="webR_URL"></iframe>
162201
}
163202
}{
164203
\ifelse{latex}{
@@ -181,23 +220,25 @@ plot(x, y, type = "b", main = "Interactive Example")
181220
This creates:
182221

183222
- Regular examples with your R code
184-
- A “WebR” section with a “View in webR REPL” button in HTML
185-
documentation or a URL in LaTeX documentation.
186-
- The button opens the code in an interactive webR session
223+
- A “WebR” section with a “Try it in your browser” and “Open in Tab”
224+
buttons in HTML documentation or a URL in LaTeX documentation.
225+
- The button opens either an embedded webR session or a new tab with the
226+
code in an interactive webR REPL.
187227

188228
> \[!NOTE\]
189229
>
190230
> The `@examplesWebR` tag uses a simplified encoding scheme compatible
191231
> with webR.
192232
193-
#### Embedded Mode
233+
#### Standalone Mode
194234

195-
For a more integrated experience, embed the webR REPL directly into the
196-
Rd file with:
235+
To avoid embedding the webR REPL, you can use the
236+
`@examplesWebR embed=false` tag. This will generate a link to the webR
237+
REPL without embedding it directly in the documentation.
197238

198239
``` r
199240
#' @examplesWebR embed
200-
#' # This code will be available in an embedded webR session
241+
#' # This code will be available in a new web browser tab with the webR REPL
201242
#' library(ggplot2)
202243
#' ggplot(mtcars, aes(mpg, wt)) +
203244
#' geom_point() +
@@ -208,15 +249,20 @@ Rd file with:
208249

209250
You can customize the `@examplesWebR` tag with additional options:
210251

211-
- `embed`: Embed an iframe instead of showing a link
212-
- `height=N`: Set iframe height in pixels (default: `300`)
252+
- `autorun`: Embed an iframe instead of showing a link (default:
253+
`"false"`)
254+
- `embed`: Embed an iframe instead of showing a link (default: `"true"`)
255+
- `height=N`: Set iframe height in pixels (default: `400`)
213256
- `version=X`: Specify webR version (default: `"latest"`)
257+
- `mode=X-Y`: Configure embedded webR interface (editor, plot, terminal,
258+
files) (default: `"editor-plot-terminal"`)
259+
- `channel=X`: Set webR communication channel (default: `"Automatic`)
214260

215261
For example, to embed with a specific height and version:
216262

217263
``` r
218-
#' @examplesWebR embed height=500 version=v0.3.3
219-
#' # Custom height iframe with specific webR version
264+
#' @examplesWebR autorun height=500 version=v0.5.4
265+
#' # Custom height iframe with specific webR version that autoruns code
220266
#' summary(cars)
221267
#' plot(cars)
222268
```

0 commit comments

Comments
 (0)