diff --git a/_extensions/webr/_extension.yml b/_extensions/webr/_extension.yml index 44dc2ed1..f36e2839 100644 --- a/_extensions/webr/_extension.yml +++ b/_extensions/webr/_extension.yml @@ -1,7 +1,7 @@ name: webr title: Embedded webr code cells author: James Joseph Balamuta -version: 0.4.0 +version: 0.4.1-dev.1 quarto-required: ">=1.2.198" contributes: filters: diff --git a/_extensions/webr/qwebr-monaco-editor-element.js b/_extensions/webr/qwebr-monaco-editor-element.js index 5644e67e..a7e4aaca 100644 --- a/_extensions/webr/qwebr-monaco-editor-element.js +++ b/_extensions/webr/qwebr-monaco-editor-element.js @@ -28,7 +28,8 @@ globalThis.qwebrCreateMonacoEditorInstance = function (cellData) { }, fontSize: '17.5pt', // Bootstrap is 1 rem renderLineHighlight: "none", // Disable current line highlighting - hideCursorInOverviewRuler: true // Remove cursor indictor in right hand side scroll bar + hideCursorInOverviewRuler: true, // Remove cursor indictor in right hand side scroll bar + readOnly: qwebrOptions['read-only'] ?? false }); // Store the official counter ID to be used in keyboard shortcuts diff --git a/_extensions/webr/webr.lua b/_extensions/webr/webr.lua index 2410af2c..92249cbc 100644 --- a/_extensions/webr/webr.lua +++ b/_extensions/webr/webr.lua @@ -65,6 +65,7 @@ local qwebRDefaultCellOptions = { ["comment"] = "", ["label"] = "", ["autorun"] = "", + ["read-only"] = "false", ["classes"] = "", ["dpi"] = 72, ["fig-cap"] = "", diff --git a/docs/qwebr-cell-options.qmd b/docs/qwebr-cell-options.qmd index 4cecb7a7..11cc718c 100644 --- a/docs/qwebr-cell-options.qmd +++ b/docs/qwebr-cell-options.qmd @@ -33,10 +33,11 @@ The `{quarto-webr}` extension does not support all of the cell options from [Qua ## quarto-webr -| Option | Default Value | Description | -|-----------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `context` | `interactive` | Describe how the cell should operate on the page through either `interactive` (Runnable code editor), `output` (Output only of executed at runtime), or `setup` (execute code without seeing output at runtime). | -| `autorun` | `false` | Allow `interactive` cells to be run during document initialization without a user pressing run code. | +| Option | Default Value | Description | +|-------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `context` | `interactive` | Describe how the cell should operate on the page through either `interactive` (Runnable code editor), `output` (Output only of executed at runtime), or `setup` (execute code without seeing output at runtime). | +| `autorun` | `false` | Allow `interactive` cells to be run during document initialization without a user pressing run code. | +| `read-only` | `false` | Prevent code in `interactive` cells from being modified by disallowing code input. | :::{.callout-note} diff --git a/docs/qwebr-code-cell-demos.qmd b/docs/qwebr-code-cell-demos.qmd index 7038736f..336fa0d5 100644 --- a/docs/qwebr-code-cell-demos.qmd +++ b/docs/qwebr-code-cell-demos.qmd @@ -70,6 +70,32 @@ print("Hello quarto-webr World!") By using these shortcuts, you can run code conveniently and efficiently. This practice can also help you become familiar with keyboard shortcuts when transitioning to integrated development environments (IDEs) like [RStudio](https://posit.co/products/open-source/rstudio/) or [Visual Studio Code with R](https://code.visualstudio.com/docs/languages/r). + +## Preventing Modifications to Code + +Code cells can be locked to their initial state by specifying `#| read-only: true`. The next code cell has such a feature implemented. Try modifying the expression `1 + 1` to any other value. + +::: {.panel-tabset} +## `{quarto-webr}` Output + +```{webr-r} +#| read-only: true +1 + 1 +``` + +## Cell code + +```{{webr-r}} +#| read-only: true +1 + 1 +``` +::: + +:::{.callout-note} +This option can be paired with `autorun: true` to avoid having the user press the "Run code" button to see the output. +::: + + ## Create a Graph with Base R For this example, webR empowers us to create and visualize data plots interactively. We can tweak labels, colors, or even the variables being used on an as-needed basis to explore "What if ..." scenarios. For instance, what if we try changing the value `blue` to `orange` and run the code again. diff --git a/docs/qwebr-release-notes.qmd b/docs/qwebr-release-notes.qmd index 15f5a29f..0fa7f090 100644 --- a/docs/qwebr-release-notes.qmd +++ b/docs/qwebr-release-notes.qmd @@ -8,6 +8,17 @@ format: toc: true --- + +# 0.4.x-dev.1: ???????????? (??-??-??) [DEV] + +## Features + +- `read-only` is a new code cell option that prevents changes to code inside of an `interactive` context. + +## Bug fixes + +## Documentation + # 0.4.0: Ball of Yarn (02-05-2024) ## Breaking changes diff --git a/tests/qwebr-test-internal-cell.qmd b/tests/qwebr-test-internal-cell.qmd index eaf5fac1..b29bf8a0 100644 --- a/tests/qwebr-test-internal-cell.qmd +++ b/tests/qwebr-test-internal-cell.qmd @@ -24,6 +24,16 @@ Test page for verifying cell context options set explicitly with `context`. 1 + 1 ``` +### Read-only + +```{webr-r} +#| context: interactive +#| read-only: true +#| autorun: true +1 + 1 +``` + + ## Setup Hidden cell that sets `x` and `y` vector values.