Skip to content

Commit e8c6822

Browse files
committed
Add first steps and incorporate the keyboard shortcut demo...
1 parent c07e56d commit e8c6822

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

docs/_quarto.yml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ website:
1616
href: https://github.com/coatless-quarto/pyodide/
1717
contents:
1818
- section: "Getting Started"
19+
contents:
20+
- href: qpyodide-first-steps.qmd
21+
text: "Your first Pyodide-powered Quarto document"
1922
- section: "Support"
2023
contents:
2124
- href: qpyodide-faq.qmd

docs/qpyodide-code-cell-demo.qmd

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ format:
1010

1111
Welcome to the world of interactive code cells, unlocked by the `quarto-pyodide` extension.
1212
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-
1413
pyodide-enabled code cell are established by using `{pyodide-python}` in a Quarto HTML document.
1514

1615
# Creating pyodide-Enabled Code Cells
@@ -56,6 +55,33 @@ Checking string length
5655
len(greet)
5756
```
5857

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:
62+
63+
- Run selected code:
64+
- macOS: <kbd>⌘</kbd> + <kbd>↩/Return</kbd>
65+
- Windows/Linux: <kbd>Ctrl</kbd> + <kbd>↩/Enter</kbd>
66+
67+
- 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).
84+
5985
## Define and Call Functions
6086

6187
Functions can be defined in one cell and called.

docs/qpyodide-first-steps.qmd

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
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

Comments
 (0)