Render quarto document with both R and python code

Viewed 107

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
---
2 Answers

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


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.

Related