Skip to content

Commit

Permalink
Reorder packages documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Aug 8, 2024
1 parent 4ec6185 commit 58d1ff4
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions docs/getting_started/packages.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,13 @@ pyodide:

{{< include ../_extensions/r-wasm/live/_knitr.qmd >}}

Both webR and Pyodide supports downloading and using additional extension packages at runtime. However, by default, `quarto-live` avoids downloading additional packages automatically. There are two supported ways to download packages:
Both webR and Pyodide supports downloading and using additional extension packages at runtime. However, outside of its dependencies, quarto-live avoids automatically downloading additional packages. There are two supported ways to download packages:

* Installing packages using interactive code blocks.
* Installing packages as the document loads.
* Installing packages using interactive code blocks.

## Installing packages

### Interactively

:::: {.panel-tabset}

## R

Install R packages interactively using the standard `install.packages()` R function.

WebR is configured to download R packages from the [webR public package repository](https://repo.r-wasm.org), and the repository website lists all R packages provided for WebAssembly.

::: {.callout-note}

By default, webR outputs information about each package installed in this way. These messages can be suppressed using the `quiet = TRUE` named argument.

:::

```{webr}
install.packages("dplyr", quiet = TRUE)
library(dplyr)
starwars |>
filter(height < 100) |>
select(name, height, mass)
```


## Python

Pyodide ships with the [micropip](https://micropip.pyodide.org/en/stable/project/usage.html) package, which can be used to install WebAssembly compatible Python packages provided by the Pyodide team using the [`micropip.install()`](https://micropip.pyodide.org/en/stable/project/api.html) function.

If a package is not found in the Pyodide repository it will be loaded from PyPI. Note that `micropip` can only load pure Python wheels or `wasm32/emscripten` WebAssembly wheels.

::: {.callout-note}

The `micropip.install()` function is asynchronous. It must be awaited before the package can be loaded.

:::

```{pyodide}
import micropip as mp
await mp.install("pandas")
import pandas as pd
pd.DataFrame({
"foo": ["az", "by", "cx", "dw"],
"bar": [3, 14, 15, 92],
"baz": [True, False, True, None],
})
```

::::

### As the document loads

To install packages as part of the document WebAssembly startup process, add a `packages` key to your document's YAML header, under the key corresponding to your chosen WebAssembly engine.
Expand Down Expand Up @@ -105,7 +52,7 @@ pyodide:

::::

## Custom repositories
#### Custom repositories

Many R and Python packages that are not available from the default webR and Pyodide repositories can still be used with `quarto-live`, with a little extra setup work.

Expand Down Expand Up @@ -146,3 +93,56 @@ pyodide:
```

::::

### Interactively

:::: {.panel-tabset}

## R

Install R packages interactively using the standard `install.packages()` R function.

WebR is configured to download R packages from the [webR public package repository](https://repo.r-wasm.org), and the repository website lists all R packages provided for WebAssembly.

::: {.callout-note}

By default, webR outputs information about each package installed in this way. These messages can be suppressed using the `quiet = TRUE` named argument.

:::

```{webr}
install.packages("dplyr", quiet = TRUE)
library(dplyr)
starwars |>
filter(height < 100) |>
select(name, height, mass)
```


## Python

Pyodide ships with the [micropip](https://micropip.pyodide.org/en/stable/project/usage.html) package, which can be used to install WebAssembly compatible Python packages provided by the Pyodide team using the [`micropip.install()`](https://micropip.pyodide.org/en/stable/project/api.html) function.

If a package is not found in the Pyodide repository it will be loaded from PyPI. Note that `micropip` can only load pure Python wheels or `wasm32/emscripten` WebAssembly wheels.

::: {.callout-note}

The `micropip.install()` function is asynchronous. It must be awaited before the package can be loaded.

:::

```{pyodide}
import micropip as mp
await mp.install("pandas")
import pandas as pd
pd.DataFrame({
"foo": ["az", "by", "cx", "dw"],
"bar": [3, 14, 15, 92],
"baz": [True, False, True, None],
})
```

::::

0 comments on commit 58d1ff4

Please sign in to comment.