Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code block language not working with "allthekernels" kernel #3459

Open
4 tasks done
knuesel opened this issue Nov 25, 2022 · 1 comment
Open
4 tasks done

Code block language not working with "allthekernels" kernel #3459

knuesel opened this issue Nov 25, 2022 · 1 comment
Labels
enhancement New feature or request jupyter
Milestone

Comments

@knuesel
Copy link
Contributor

knuesel commented Nov 25, 2022

Bug description

Still looking for a good solution to #135, I found https://github.com/minrk/allthekernels which seems like a great candidate: it's a simple Jupyter kernel that forwards code cells to different sub-kernels for different languages (this also seems to be the approach favored by the Jupyter developers, see jupyterlab/jupyterlab#2815).

However I found some issues trying to use it with Quarto. Here's my test document a.qmd:

---
jupyter: atk
---

```{any}
>python3
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])

2+2
```

```{any}
>octave
plot(magic(2))

2+2
```

First, two issues that should be fixed outside of Quarto I think:

  • Calling quarto render a.qmd gives ERROR: TypeError: Cannot read properties of undefined (reading 'toLowerCase'). This is because the kernel.json doesn't define a language. The language key is required so this should probably be fixed in allthekernels. I fixed it by adding "language": "any" in the kernel.json.

  • With the above fix, calling quarto render a.qmd sometimes produces an HTML file with code cells but empty outputs. It looks like a latency issue: it normally works the second time (once the daemon is running). The same issue can be observed when running the cells in Jupyter Notebook so it's probably a problem in allthekernels.

Now the issue that should be fixed in Quarto I think: The execution requires that I mark code blocks with {any} to match the language declared in kernel.json. Due to this the code blocks are not formatted properly: no syntax highlighting and not even a gray background. What I would expect instead is to write

```{octave}
>octave
plot(magic(2))

2+2
```

and have it work as long as I have defined jupyter: atk. If this worked I could also write a Lua filter to infer the >octave line from the block language and insert it automatically.

Note: the same issue affects the SoS kernel (another polyglot kernel that additionally enables data exchange between the sub-kernels).

Tested with quarto 1.2.269 and 1.3.26 on Pop!_OS 22.04.

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
@knuesel knuesel added the bug Something isn't working label Nov 25, 2022
@knuesel
Copy link
Contributor Author

knuesel commented Nov 25, 2022

Maybe it's useful to explain while knitr is not good enough... Knitr is great for mixing R, Python and Julia thanks to reticulate and JuliaCall, but for other languages it's very limited: each cell is run in a different session and graphical outputs are not displayed. The proxy kernel approach doesn't have these problems, and for each language it gives access to the features of the specialized kernel (configuration, magics...)

@cscheid cscheid added enhancement New feature or request and removed bug Something isn't working labels Nov 27, 2022
@cscheid cscheid added this to the Future milestone Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jupyter
Projects
None yet
Development

No branches or pull requests

2 participants