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/config.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,6 +200,48 @@ toc: false
200
200
201
201
Whether to enable [search](./search) on the project; defaults to false.
202
202
203
+
## interpreters
204
+
205
+
The **interpreters** option specifies additional interpreted languages for data loaders, indicating the file extension and associated interpreter. (See [loader routing](./loaders#routing) for more.) The default list of interpreters is:
Keys specify the file extension and values the associated command and arguments. For example, to add Perl (extension `.pl`) and AppleScript (`.scpt`) to the list above:
225
+
226
+
```js run=false
227
+
exportdefault {
228
+
interpreters: {
229
+
".pl": ["perl"],
230
+
".scpt": ["osascript"]
231
+
}
232
+
};
233
+
```
234
+
235
+
To disable an interpreter, set its value to null. For example, to disable Rust:
236
+
237
+
```js run=false
238
+
exportdefault {
239
+
interpreters: {
240
+
".rs":null
241
+
}
242
+
};
243
+
```
244
+
203
245
## markdownIt <ahref="https://github.com/observablehq/framework/releases/tag/v1.1.0"target="_blank"class="observablehq-version-badge"data-version="^1.1.0"title="Added in v1.1.0"></a>
204
246
205
247
A hook for registering additional [markdown-it](https://github.com/markdown-it/markdown-it) plugins. For example, to use [markdown-it-footnote](https://github.com/markdown-it/markdown-it-footnote):
Copy file name to clipboardExpand all lines: docs/loaders.md
+36-16Lines changed: 36 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,29 +126,49 @@ Like with any other file, these files from generated archives are live in previe
126
126
127
127
## Routing
128
128
129
-
Data loaders live in the source root (typically `docs`) alongside your other source files. When a file is referenced from JavaScript via `FileAttachment`, if the file does not exist, Observable Framework will look for a file of the same name with a double extension to see if there is a corresponding data loader. The following second extensions are checked, in order, with the corresponding language and interpreter:
129
+
Data loaders live in the source root (typically `docs`) alongside your other source files. When a file is referenced from JavaScript via `FileAttachment`, if the file does not exist, Observable Framework will look for a file of the same name with a double extension to see if there is a corresponding data loader. By default, the following second extensions are checked, in order, with the corresponding language and interpreter:
130
130
131
131
-`.js` - JavaScript (`node`)
132
132
-`.ts` - TypeScript (`tsx`)
133
133
-`.py` - Python (`python3`)
134
134
-`.R` - R (`Rscript`)
135
135
-`.rs` - Rust (`rust-script`)
136
136
-`.go` - Go (`go run`)
137
+
-`.java` — Java (`java`; requires Java 11+ and [single-file programs](https://openjdk.org/jeps/330))
138
+
-`.jl` - Julia (`julia`)
139
+
-`.php` - PHP (`php`)
137
140
-`.sh` - shell script (`sh`)
138
141
-`.exe` - arbitrary executable
139
142
140
-
For example, for the file `quakes.csv`, the following data loaders are considered:
143
+
For example, for the file `quakes.csv`, the following data loaders are considered:`quakes.csv.js`, `quakes.csv.ts`, `quakes.csv.py`, _etc._ The first match is used.
141
144
142
-
-`quakes.csv.js`
143
-
-`quakes.csv.ts`
144
-
-`quakes.csv.py`
145
-
-`quakes.csv.R`
146
-
-`quakes.csv.rs`
147
-
-`quakes.csv.go`
148
-
-`quakes.csv.sh`
149
-
-`quakes.csv.exe`
145
+
<divclass="tip">The <b>interpreters</b> <ahref="./config#interpreters">configuration option</a> can be used to extend the list of supported extensions.</div>
150
146
151
-
If you use `.py`, `.R`, `.rs`, or `.go`, the corresponding interpreter (`python3`, `Rscript`, `rust-script`, or `go run`, respectively) must be installed and available on your `$PATH`. Any additional modules, packages, libraries, _etc._, must also be installed before you can use them.
147
+
To use an interpreted data loader (anything other than `.exe`), the corresponding interpreter must be installed and available on your `$PATH`. Any additional modules, packages, libraries, _etc._, must also be installed. Some interpreters are not available on all platforms; for example `sh` is only available on Unix-like systems.
148
+
149
+
<divclass="tip">
150
+
151
+
You can use a virtual environment in Python, such as [uv](https://github.com/astral-sh/uv), to install libraries locally to the project. This is useful when working in multiple projects, and when collaborating; you can also track dependencies in a `requirements.txt` file. To create a virtual environment with uv, run:
152
+
153
+
```sh
154
+
uv venv # Create a virtual environment at .venv.
155
+
```
156
+
157
+
To activate the virtual environment on macOS or Linux:
158
+
159
+
```sh
160
+
source .venv/bin/activate
161
+
```
162
+
163
+
Or on Windows:
164
+
165
+
```sh
166
+
.venv\Scripts\activate
167
+
```
168
+
169
+
You can then run the `observable preview` or `observable build` commands as usual; data loaders will run within the virtual environment. Run the `deactivate` command to exit the virtual environment.
170
+
171
+
</div>
152
172
153
173
Data loaders are run in the same working directory in which you run the `observable build` or `observable preview` command, which is typically the project root. In Node, you can access the current working directory by calling `process.cwd()`, and the data loader’s source location with [`import.meta.url`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta). To compute the path of a file relative to the data loader source (rather than relative to the current working directory), use [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve). For example, a data loader in `docs/summary.txt.js` could read the file `docs/table.txt` as:
154
174
@@ -159,18 +179,18 @@ import {fileURLToPath} from "node:url";
Whereas `.js`, `.ts`, `.py`, `.R`, `.rs`, `.go`, and `.sh` data loaders are run via interpreters, `.exe` data loaders are run directly and must have the executable bit set. This is typically done via [`chmod`](https://en.wikipedia.org/wiki/Chmod). For example:
182
+
Executable (`.exe`) data loaders are run directly and must have the executable bit set. This is typically done via [`chmod`](https://en.wikipedia.org/wiki/Chmod). For example:
163
183
164
184
```sh
165
185
chmod +x docs/quakes.csv.exe
166
186
```
167
187
168
-
While a `.exe` data loader may be any binary executable (_e.g.,_ compiled from C), it is often convenient to specify another interpreter using a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>). For example, to write a data loader in Julia:
188
+
While a `.exe` data loader may be any binary executable (_e.g.,_ compiled from C), it is often convenient to specify another interpreter using a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>). For example, to write a data loader in Perl:
169
189
170
-
```julia
171
-
#!/usr/bin/env julia
190
+
```perl
191
+
#!/usr/bin/env perl
172
192
173
-
println("hello world")
193
+
print("Hello World\n");
174
194
```
175
195
176
196
If multiple requests are made concurrently for the same data loader, the data loader will only run once; each concurrent request will receive the same response.
Copy file name to clipboardExpand all lines: examples/eia/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,14 +29,14 @@ The base map is created in the `us-states.json.js` data loader, which uses [Topo
29
29
30
30
### Static files
31
31
32
-
Several static files used in the dashboard were downloaded from the EIA Hourly Electric Grid Monitor [About page](https://www.eia.gov/electricity/gridmonitor/about) (EIA-930 data reference tables), and not created or processed in data loaders. These files contain reference information that expect to remain unchanged, including:
32
+
Several static files used in the dashboard were downloaded from the EIA Hourly Electric Grid Monitor [About page](https://www.eia.gov/electricity/gridmonitor/about) (EIA-930 data reference tables), and not created or processed in data loaders. These files contain reference information that expect to remain unchanged, including:
33
33
34
-
-`eia-bia-reference.csv`: Reference information about balancing authority name, time zone, region, country, etc.
34
+
-`eia-bia-reference.csv`: Reference information about balancing authority name, time zone, region, country, _etc._
35
35
-`eia-connections-reference.csv`: Reference information about connections between balancing authorities
36
36
37
37
## Charts
38
38
39
-
The charts and map are drawn with [Observable Plot](https://observablehq.com/plot/), and saved as components in `components/charts.js` and `components/map.js` to simplify our layout code in `index.md`.
39
+
The charts and map are drawn with [Observable Plot](https://observablehq.com/plot/), and saved as components in `components/charts.js` and `components/map.js` to simplify our layout code in `index.md`.
Copy file name to clipboardExpand all lines: examples/plot/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ The [`npm-downloads.csv.ts`](./docs/data/npm-downloads.csv.ts) loader retrieves
28
28
29
29
## Big numbers
30
30
31
-
Key performance indicators are displayed as “big numbers” with, in some cases, a trend indicating growth over one week. Their layout is using the convenience CSS classes _big_, _red_etc.
31
+
Key performance indicators are displayed as “big numbers” with, in some cases, a trend indicating growth over one week. Their layout is using the convenience CSS classes _big_, _red__etc._
0 commit comments