Skip to content

Commit

Permalink
Add readonly option
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless committed Feb 23, 2024
1 parent cd9a862 commit 38ac022
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion _extensions/webr/_extension.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 2 additions & 1 deletion _extensions/webr/qwebr-monaco-editor-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions _extensions/webr/webr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ local qwebRDefaultCellOptions = {
["comment"] = "",
["label"] = "",
["autorun"] = "",
["read-only"] = "false",
["classes"] = "",
["dpi"] = 72,
["fig-cap"] = "",
Expand Down
9 changes: 5 additions & 4 deletions docs/qwebr-cell-options.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
26 changes: 26 additions & 0 deletions docs/qwebr-code-cell-demos.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions docs/qwebr-release-notes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/qwebr-test-internal-cell.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 38ac022

Please sign in to comment.