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
---
2
  • Can you share your yaml section?! Commented Sep 11, 2022 at 0:05
  • Thanks for the interest. I added the yaml. Commented Sep 11, 2022 at 0:53

3 Answers 3

5

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


Sign up to request clarification or add additional context in comments.

1 Comment

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

See the relevant quarto documentation

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.