Demo: Set Global Cell Options


This feature is currently experimental and is included in 0.4.2-dev.1 build of {quarto-webr}.


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.

cell-options Document Key

To establish default cell behavior, you can utilize the cell-options subkey in webr. For instance, consider the following structure:

    <cell-option>: <value>

Here, <cell-option> and <value> represent one of the supported cell options.

Restricting Access

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:

title: "Demo: Set Global Cell Options"
engine: knitr
    out-width: "100%"
    autorun: true
    read-only: true
  - webr

Let’s observe the outcome with a cell like this:

fit = lm(mpg ~ am, data = mtcars)

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.

#| read-only: false


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.