dzegpi
dzegpi

Reputation: 688

Render quarto document with both R and python code

I'm using quarto html format to produce a document with both python and R code. The rendering was smooth until I added the first python lines of python code:

import requests
url = 'some/url'
page = requests.get(url)

The code works just fine without rendering, so I can't spot my mistake.

This is the error message from the RStudio "Background Jobs" pane:

Jupyter is not available in this Python installation.
Install with py -m pip install jupyter

Should I install jupyter, even if I'm using the knitr engine for rendering?

EDIT (YAML section)

---
title: "Web scrapping"
author: "Diabb Zegpi"
format: 
  html:
    self-contained: true
    theme: [default, custom.scss]
editor: visual
lang: es
editor_options: 
  chunk_output_type: inline
---

Upvotes: 4

Views: 2584

Answers (3)

GMG
GMG

Reputation: 21

See the relevant quarto documentation

This suggests you need to have engine: knitr in your yaml

Upvotes: 2

dzegpi
dzegpi

Reputation: 688

The rendering worked after running tthe suggested line in the terminal:

py -m pip install jupyter

I still don't know why and what jupyter has to do with knitr rendering.

Upvotes: 0

Shafee
Shafee

Reputation: 20027

You can render a document with both R and python code with the knitr engine specified, if you have the {reticulate} r-package installed in your computer. Also note that, for knitr to identify the python code you need to use python as the chunk header.

---
title: "R and Python"
format: html
engine: knitr
---

## R

```{r}
x = sample(1:100, size = 1000, replace = TRUE)
y = rnorm(1000, mean = 40, sd = 2)

plot(x, y)
```


## python

```{python}
import requests

x = requests.get('https://www.wikipedia.org/')

print(x.text)
```

quarto rendered html output with R and python code


Upvotes: 5

Related Questions