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
Copy file name to clipboardexpand all lines: docs/qpyodide-code-cell-demo.qmd
+27-1
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,6 @@ format:
10
10
11
11
Welcome to the world of interactive code cells, unlocked by the `quarto-pyodide` extension.
12
12
These cells allow you to run Python code directly within your Quarto HTML documents, enabling real-time computations and more. Let's explore the impressive capabilities `pyodide` offers.
13
-
14
13
pyodide-enabled code cell are established by using `{pyodide-python}` in a Quarto HTML document.
15
14
16
15
# Creating pyodide-Enabled Code Cells
@@ -56,6 +55,33 @@ Checking string length
56
55
len(greet)
57
56
```
58
57
58
+
59
+
## Line-by-line Execution
60
+
61
+
In this section, we'll explore the built-in keyboard shortcuts for executing code within the interactive code cell. You can run either the selected code or specific lines or the entire cell with the following keyboard shortcuts:
- To run the entire code cell, you can simply click the "Run code" button, or use the keyboard shortcut:
68
+
- <kbd>Shift</kbd> + <kbd>↩</kbd>
69
+
70
+
Feel free to try it out in the following code cell:
71
+
72
+
```{pyodide-python}
73
+
# Try running selected code at the start of the line
74
+
print("Hello quarto-pyodide World!")
75
+
76
+
# Try highlight only -3 or 5 and pressing the keys required
77
+
# for the "selected code" approach
78
+
-3 + 5
79
+
80
+
# Finally, try running the entire code cell by using Shift + ↩
81
+
```
82
+
83
+
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 Python](https://code.visualstudio.com/docs/languages/python).
title: "Making your first Pyodide-powered Quarto document"
3
+
author: "James Joseph Balamuta"
4
+
date: "02-19-2024"
5
+
date-modified: last-modified
6
+
format:
7
+
html:
8
+
toc: true
9
+
filters:
10
+
- pyodide
11
+
---
12
+
13
+
## Installation
14
+
15
+
To use this extension in a [Quarto project](https://quarto.org/docs/projects/quarto-projects.html), install it from within the project's working directory by typing into **Terminal**:
16
+
17
+
```bash
18
+
quarto add coatless-quarto/pyodide
19
+
```
20
+
21
+
:::callout-note
22
+
Quarto extensions are project-specific installations and are not stored in a global library. This means that for every new Quarto project or directory where you create a Quarto Document, you'll need to install the extension again.
23
+
:::
24
+
25
+
## Usage
26
+
27
+
Once the extension is successfully installed, you can begin utilizing it in your Quarto documents located within the same working directory as the `_extensions` folder. To activate the `Pyodide` functionality in those documents, follow these steps:
28
+
29
+
1.**Add `pyodide` Filter**: In the header of your Quarto document, add the `pyodide` filter to the list of filters:
30
+
31
+
```yaml
32
+
filters:
33
+
- pyodide
34
+
```
35
+
36
+
2. **Use `{pyodide-python}` Code Blocks**: Write your Python code within code blocks marked with `{pyodide-python}`. Here's an example:
37
+
38
+
````markdown
39
+
---
40
+
title: Pyodide in Quarto HTML Documents
41
+
format: html
42
+
filters:
43
+
- pyodide
44
+
---
45
+
46
+
This is a Pyodide-enabled code cell in a Quarto HTML document.
47
+
48
+
```{pyodide-python}
49
+
n = 5
50
+
while n > 0:
51
+
print(n)
52
+
n = n - 1
53
+
54
+
print('Blastoff!')
55
+
```
56
+
````
57
+
58
+
3. **Render Your Document**: You can now render your Quarto document by clicking on the **Preview** (or use the keyboard shortcut <kbd>⇧⌘K</kbd> on macOS or <kbd>Ctrl+Shift+K</kbd> on Windows/Linux). The document will execute under `engine: jupyter` by default, but you can specify a different engine if needed.
59
+
60
+
:::callout-note
61
+
If an engine is not specified, Quarto will attempt to use the `jupyter` compute engine by default. This may cause an error if `jupyter` is not installed on your computer.
62
+
:::
63
+
64
+
4. **Explore interactivity**: Try out the rendered code cell by pressing the "Run Code" button or using a keyboard shortcut of <kbd>Shift</kbd> + <kbd>↩</kbd>.
65
+
66
+
```{pyodide-python}
67
+
n = 5
68
+
while n > 0:
69
+
print(n)
70
+
n = n - 1
71
+
72
+
print('Blastoff!')
73
+
```
74
+
75
+
# Fin
76
+
77
+
In summary, this guide has provided an overview of how to incorporate the `quarto-pyodide` extension into your Quarto HTML documents using VS Code. We explored key workflow changes necessary for incorporating interactive Python code into your Quarto HTML documents, from installation to document rendering.
78
+
79
+
For your next steps consider looking at different use cases for [interactive options](qpyodide-code-cell-demos.qmd).
0 commit comments