haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
689 stars 147 forks source link

Kable works in RStudio but not JupyterLab w R kernel #620

Open sjgenco opened 3 years ago

sjgenco commented 3 years ago

Description

I posted this yesterday as a JupyterLab issue (https://github.com/jupyterlab/jupyterlab/issues/10290#issue-901554910), but I thought I should post it here as well. I don't think this is a Kable problem, but wanted to cover both bases.

I'm trying to generate nice-looking tables in JupyterLab using library(kableExtra) All the simple examples from the knitr::kable site work fine in RStudio but only produce xml html output in JupyterLab. I haven't found anything here in 'Issues' or elsewhere on the web that hints at a solution. Surprising to me, since this seems pretty fundamental.

Reproduce

To reproduce, run this code snippet used for examples on the KableExtras site (after install.packages("kableExtra") of course ...

library(kableExtra)
dt <- mtcars[1:5, 1:6]
dt %>%
    kbl() %>%
    kable_styling()

If you run this in RStudio, you get this result in the Viewer. RStudio-kable-formatting

But if you run it in JupyterLab (versions & environment are described in the original post), you get this result (truncated here). It's just outputting the html, not converting it into a formatted table, as it should. JupyterLab-kable-not-formatting

That's the issue.

Expected behavior

I expected the table to format properly in JupyterLab, like in RStudio

Context

I've read that this problem may relate to the problem with trying to export a JupyterLab notebook to PDF. I had that problem too. Read a lot about pandoc and nbconvert and xelatex and getting xelatex into the $PATH. Just want to note that I have installed latest versions of MacTex and all those pkgs, and xelatex IS in my PATH:

(r_env) xxxxxxx@x86_64-apple-darwin13 ~ % echo $path
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/TeX/texbin /opt/X11/bin /Users/xxxxxxxopt/anaconda3/envs/r_env/bin /Users/xxxxxxx/opt/anaconda3/condabin

By the way, the 'Export Notebook as ... PDF' still doesn't work inside JupyterLab, giving the familiar (and apparently incorrect) error: nbconvert failed: xelatex not found on PATH, if you have not installed xelatex you may need to do so. But I can get that export to work when I run it from the command line in terminal: jupyter nbconvert --to PDF notebook.ipynb which is another indication that all the pieces are in place, JupyterLab is simply not doing the expected conversions.

Thanks for any ideas you might have!

haozhu233 commented 3 years ago

This is certainly something I would like to improve but I'm fairly short with time. For HTML table, a temporary solution is provided here: https://stackoverflow.com/questions/46531571/how-do-i-format-an-r-table-in-an-r-jupyter-notebook/46532394#46532394 (note that not all features are available because it won't load css)

For latex, jupyter's latex engine isn't as flexible as rmarkdown's engine. I haven't got a chance to look closer though.