4

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
---
dzegpi
  • 554
  • 5
  • 14

3 Answers3

3

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


shafee
  • 15,566
  • 3
  • 19
  • 47
  • As the question states, the python code ran successfully in the editor, but the rendering was failing. Suddenly, everything worked after installing jupyter. I don't know why, because I selected knitr as the engine for the quarto document, although is not specified in the YAML. – dzegpi Sep 12 '22 at 14:50
1

See the relevant quarto documentation

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

GMG
  • 11
  • 1
0

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.

dzegpi
  • 554
  • 5
  • 14