Skip to content

Commit d175acf

Browse files
committed
Add guides
1 parent bf5bf26 commit d175acf

File tree

3 files changed

+246
-0
lines changed

3 files changed

+246
-0
lines changed

docs/_quarto.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ website:
1515
contents:
1616
- text: "Home"
1717
file: index.qmd
18+
- section: "Examples"
19+
contents:
20+
- text: "Toggle for All Cells"
21+
href: qtoggle-all-cells.qmd
22+
- text: "Toggle Specific Cells"
23+
href: qtoggle-specific-cells.qmd
1824
- section: "Support"
1925
contents:
2026
- text: "FAQ"

docs/qtoggle-all-cells-example.qmd

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: "Toggle for All Cells"
3+
format:
4+
html:
5+
toc: true
6+
toggle:
7+
output-toggle: true # Enable toggle buttons for all cells
8+
output-hidden: false # Show outputs initially (default)
9+
filters:
10+
- toggle
11+
---
12+
13+
This page demonstrates how to globally enable toggle functionality
14+
for all code cells, rather than enabling it on a per cell configuration.
15+
This approach allows you to skip individual cell configurations unless
16+
you want to override the global behavior.
17+
18+
## Setup
19+
20+
To enable toggle for all cells, add this to your document's YAML header:
21+
22+
```yaml
23+
---
24+
title: "Your Document Title"
25+
format: html
26+
toggle:
27+
output-toggle: true # Automatically add toggle to all cells
28+
output-hidden: false # Show outputs by default
29+
filters: [toggle]
30+
---
31+
```
32+
33+
With this set, every code cell that produces an output gets a toggle button
34+
automatically and outputs are visible by default. Readers can hide them if
35+
they choose.
36+
37+
This means:
38+
39+
- No need to add `toggle: true` to individual cells as it will apply to all.
40+
- Outputs are visible by default (readers can hide them)
41+
- Consistent experience across your entire document
42+
43+
Hover over code blocks to see toggle buttons. `"⌄"` = visible, `"›"` = hidden.
44+
45+
## Python Examples
46+
47+
### Output
48+
49+
```{python}
50+
print("Hello, world!")
51+
print("This has a toggle button.")
52+
```
53+
54+
### Math Operations
55+
56+
```{python}
57+
numbers = [1, 2, 3, 4, 5]
58+
print(f"Sum: {sum(numbers)}")
59+
print(f"Average: {sum(numbers)/len(numbers)}")
60+
```
61+
62+
### Plotting with Matplotlib
63+
64+
```{python}
65+
import matplotlib.pyplot as plt
66+
plt.plot([1, 2, 3], [1, 4, 9], 'o-')
67+
plt.title("Simple Plot")
68+
plt.show()
69+
```
70+
71+
## R Examples
72+
73+
### Statistics Calculations
74+
75+
```{r}
76+
data <- c(10, 20, 30, 40, 50)
77+
cat("Mean:", mean(data), "\n")
78+
cat("Max:", max(data), "\n")
79+
```
80+
81+
### Graphing with Base R
82+
83+
```{r}
84+
barplot(c(23, 45, 32), names.arg = c("A", "B", "C"))
85+
```
86+
87+
## Override Options
88+
89+
### Always Show
90+
91+
No toggle button will be added, output is always visible.
92+
93+
```{python}
94+
#| toggle: false
95+
print("Always visible - no toggle button")
96+
```
97+
98+
### Hidden by Default
99+
100+
Starts hidden - click toggle to show
101+
102+
```{python}
103+
#| output-hidden: true
104+
print("You've clicked the toggle button to show me!")
105+
```
106+
107+
## Other Languages
108+
109+
### Bash
110+
111+
```{bash}
112+
echo "Current date:"
113+
date
114+
```
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
title: "Toggle Specific Cells"
3+
format:
4+
html:
5+
toc: true
6+
code-fold: true
7+
code-summary: "Show code"
8+
filters:
9+
- toggle
10+
---
11+
12+
This page demonstrates how to selectively enable toggle functionality
13+
for specific code cells, rather than enabling it document-wide. This
14+
approach gives you precise control over which cells have toggle buttons.
15+
16+
## Setup
17+
18+
To enable selective toggle, use this minimal setup:
19+
20+
```yaml
21+
---
22+
title: "Your Document Title"
23+
format: html
24+
filters: [toggle]
25+
---
26+
```
27+
28+
The `filters: [toggle]` enables the toggle extension for the document
29+
so that only cells with `toggle: true` get toggle buttons.
30+
31+
## Examples
32+
33+
### Important Results (No Toggle)
34+
35+
```{python}
36+
total = 1500
37+
target = 1200
38+
print(f"Sales: ${total} (Target: ${target})")
39+
```
40+
41+
### Details (With Toggle)
42+
43+
```{python}
44+
#| toggle: true
45+
breakdown = [400, 500, 600]
46+
for i, amount in enumerate(breakdown, 1):
47+
print(f"Q{i}: ${amount}")
48+
```
49+
50+
### Debug Info (Hidden by Default)
51+
52+
```{python}
53+
#| toggle: true
54+
#| output-hidden: true
55+
print("Processing time: 2.3s")
56+
print("Memory: 45MB")
57+
```
58+
59+
## R Examples
60+
61+
### Key Results (No Toggle)
62+
63+
```{r}
64+
scores <- c(85, 90, 78, 92)
65+
cat("Average:", mean(scores), "\n")
66+
```
67+
68+
### Analysis (With Toggle)
69+
70+
```{r}
71+
#| toggle: true
72+
scores <- c(85, 90, 78, 92)
73+
cat("Min:", min(scores), "Max:", max(scores), "\n")
74+
```
75+
76+
### Visualization (With Toggle)
77+
78+
```{r}
79+
#| toggle: true
80+
hist(c(85, 90, 78, 92), main = "Scores")
81+
```
82+
83+
## Mixed Strategy
84+
85+
### Summary (Always Visible)
86+
87+
```{python}
88+
risk = "Medium"
89+
confidence = 89
90+
print(f"Risk: {risk} ({confidence}% confidence)")
91+
```
92+
93+
### Supporting Data (Toggle)
94+
95+
```{python}
96+
#| toggle: true
97+
factors = {"Market": 3.2, "Credit": 2.8}
98+
for name, score in factors.items():
99+
print(f"{name}: {score}")
100+
```
101+
102+
### Technical Notes (Hidden)
103+
104+
```{python}
105+
#| toggle: true
106+
#| output-hidden: true
107+
print("Model v2.1.3")
108+
print("Updated: 2024-05-28")
109+
```
110+
111+
## With Code Folding
112+
113+
This page uses `code-fold: true` so you can control code and output independently.
114+
115+
### Function Example
116+
117+
```{python}
118+
#| toggle: true
119+
def growth_rate(current, previous):
120+
return (current - previous) / previous * 100
121+
122+
result = growth_rate(1500, 1200)
123+
print(f"Growth: {result:.1f}%")
124+
```
125+
126+
Use `toggle: true` for optional details. Keep key results without toggles.

0 commit comments

Comments
 (0)