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
* Add yaml-key for cell defaults
Allow user to define code cell defaults in yaml
* user defined editor font size
Add a cell option for editor-font-size.
You might perhaps want a different name?
* Add an example
* Remove font change from this PR as we're wanting to just focus on global settings.
* Bump extension version
* Re-write simple example to focus on the global feature
* Switch to using `cell-defaults` in lua filter
* Add a test case file
* Add release note
* Add documentation on the key
* Switch from `cell-defaults` to `cell-options`
* Switch from `cell-defaults` to `cell-options`
---------
Co-authored-by: James J Balamuta <[email protected]>
This feature is currently experimental and is included in 0.4.2-dev.1 build of `{quarto-webr}`.
15
+
:::
16
+
17
+
# Overview
18
+
19
+
This demo illustrates how to set cell-level options for the entire document by specifying them in the document header. Once established, these options govern the behavior and appearance of `{webr-r}` code cells. However, they can be overridden locally by specifying cell options within individual `{webr-r}` cells.
20
+
21
+
## `cell-options` Document Key
22
+
23
+
To establish default cell behavior, you can utilize the `cell-options` subkey in `webr`. For instance, consider the following structure:
24
+
25
+
```yaml
26
+
webr:
27
+
cell-options:
28
+
<cell-option>: <value>
29
+
```
30
+
31
+
Here, `<cell-option>` and `<value>` represent one of the [supported cell options](../qwebr-cell-options.qmd).
32
+
33
+
## Restricting Access
34
+
35
+
An example use case is to prevent modifications to interactive code cells while ensuring their content is executed. In this document, we've defined the global behavior with:
36
+
37
+
```md
38
+
---
39
+
title: "Demo: Set Global Cell Options"
40
+
engine: knitr
41
+
webr:
42
+
cell-options:
43
+
out-width: "100%"
44
+
autorun: true
45
+
read-only: true
46
+
filters:
47
+
- webr
48
+
---
49
+
```
50
+
51
+
Let's observe the outcome with a cell like this:
52
+
53
+
::: {.panel-tabset group="language"}
54
+
#### `{quarto-webr}` Output
55
+
```{webr-r}
56
+
fit = lm(mpg ~ am, data = mtcars)
57
+
summary(fit)
58
+
```
59
+
#### Cell Code
60
+
````md
61
+
```{webr-r}
62
+
fit = lm(mpg ~ am, data = mtcars)
63
+
summary(fit)
64
+
```
65
+
````
66
+
:::
67
+
68
+
Attempting to modify the cell will be ineffective. However, in the subsequent cell, we've specified a local option that overrides the document's default, allowing modification. Feel free to try modifying the cell below.
69
+
70
+
::: {.panel-tabset group="language"}
71
+
#### `{quarto-webr}` Output
72
+
```{webr-r}
73
+
#| read-only: false
74
+
plot(fit)
75
+
```
76
+
#### Cell Code
77
+
````md
78
+
```{webr-r}
79
+
#| read-only: false
80
+
plot(fit)
81
+
```
82
+
````
83
+
:::
84
+
85
+
# Conclusion
86
+
87
+
This approach eliminates the need to repeatedly specify options across multiple cells within the document, consolidating them in a single location. Should the need arise, you can always override the behavior by specifying a local value for the cell.
Copy file name to clipboardexpand all lines: docs/qwebr-meta-options.qmd
+22-1
Original file line number
Diff line number
Diff line change
@@ -106,27 +106,48 @@ The extension also provides native options that affect its behavior:
106
106
107
107
- **Description**: Controls the display of the WebR initialization state in the document header.
108
108
- **Default Value**: `true`
109
+
- **Demo Document**: [Setting Options in Document Header](demos/qwebr-setting-options-in-document-yaml.qmd)
109
110
110
111
### `show-header-message`
111
112
112
113
- **Description**: Determines whether COOP and COEP headers are in use for faster page loads.
113
114
- **Default Value**: `false`
115
+
- **Demo Document**: [Setting Options in Document Header](demos/qwebr-setting-options-in-document-yaml.qmd)
116
+
117
+
### `cell-options`
118
+
119
+
- **Description**: Modifies default cell options for `{webr-r}` cells.
120
+
- **Default Value**: Please see [Code Cell Options](qwebr-cell-options.qmd) for individual cell option defaults.
121
+
- **Demo Document**: [Set Global Cell Options](demos/qwebr-global-cell-defaults.qmd)
122
+
- **Example:**
123
+
124
+
```yaml
125
+
webr:
126
+
cell-options:
127
+
autorun: true
128
+
fig-height: 400
129
+
fig-width: 300
130
+
```
131
+
132
+
This modifies the default cell options for `autorun`, `fig-width`, and `fig-height` for all cells in the document.
114
133
115
134
### `repos`
116
135
117
136
- **Description**: Specify the repository locations to search for R packages when trying to install them in array form. Regardless of values specified, we will always conclude by checking to see if the package is present in the main webR repository: <https://repo.r-wasm.org/>.
- **Demo Document**: [Custom R WASM Package Repository](demos/qwebr-custom-repository.qmd)
119
139
- **Example**: `['https://username.r-universe.dev', 'https://username.github.io/reponame']` will cause webR to first look for the package on `r-universe.dev`, then move to looking at the package on GitHub Pages, before finally landing on the official repository.
120
140
121
-
122
141
### `packages`
123
142
124
143
- **Description**: Specifies R packages to install automatically when the document opens.
125
144
- **Default Value**: `[]`
145
+
- **Demo Document**: [Setting Options in Document Header](demos/qwebr-setting-options-in-document-yaml.qmd)
126
146
- **Example:** `['ggplot2', 'dplyr']` will cause `ggplot2` and `dplyr` to be installed.
127
147
128
148
### `autoload-packages`
129
149
130
150
- **Description**: The `autoload-packages` option allows you to control whether R packages specified in the `packages` document option will be automatically loaded using `library()` calls when the document opens. By default, this option is set to `true`, meaning that packages listed in the `packages` option will be automatically loaded. If you set it to `false`, you will need to include a code cell with `library(package)` function calls for each package in `packages`.
131
151
- **Default Value**: `true`
152
+
- **Demo Document**: [Setting Options in Document Header](demos/qwebr-setting-options-in-document-yaml.qmd)
Copy file name to clipboardexpand all lines: docs/qwebr-release-notes.qmd
+14
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,20 @@ format:
8
8
toc: true
9
9
---
10
10
11
+
# 0.4.2-dev.1: ??????? (??-??-??)
12
+
13
+
:::{.callout-note}
14
+
Features listed under the `-dev` version have not yet been solidified and may change at any point.
15
+
:::
16
+
17
+
## Features
18
+
19
+
- Added `cell-options` document-level option to specify global defaults for `{webr-r}` options ([#173](https://github.com/coatless/quarto-webr/pulls/173), thanks [ute](https://github.com/ute)!)
0 commit comments