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

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

Open
sjgenco opened this issue May 26, 2021 · 12 comments
Open

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

sjgenco opened this issue May 26, 2021 · 12 comments

Comments

@sjgenco
Copy link

sjgenco commented May 26, 2021

Description

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

Here's the simple R code example from the Kable site

library(kableExtra)
dt <- mtcars[1:5, 1:6]
head(dt)

this works as expected in both RStudio & JupyterLab

now try this simple kable_styling command

dt %>%
    kbl() %>%
    kable_styling()

In RStudio, I get a nicely formatted table in the 'Viewer' pane. Other kable options and styles also work as expected.

In JupyterLab I get this:

   <td style="text-align:right;"> 160 </td>
   <td style="text-align:right;"> 110 </td>
   <td style="text-align:right;"> 3.90 </td>
   <td style="text-align:right;"> 2.620 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> Mazda RX4 Wag </td>
   <td style="text-align:right;"> 21.0 </td>  ...

... and so on

Expected behavior

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

Context

  • Operating System and version: MacBook Pro 16, Big Sur 11.3.1
  • Browser and version: Chrome Version 90.0.4430.212 (Official Build) (x86_64)
  • JupyterLab version: 3.0.14

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!

@welcome
Copy link

welcome bot commented May 26, 2021

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@agoose77
Copy link
Contributor

agoose77 commented May 26, 2021

Could you post a screenshot of what you expect to see vs what you actually see? For example, for this Conda environment (see details)

name: test-r-kernel
channels:
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=conda_forge
  - _openmp_mutex=4.5=1_gnu
  - _r-mutex=1.0.1=anacondar_1
  - anyio=3.1.0=py39hf3d152e_0
  - argon2-cffi=20.1.0=py39h3811e60_2
  - async_generator=1.10=py_0
  - attrs=21.2.0=pyhd8ed1ab_0
  - babel=2.9.1=pyh44b312d_0
  - backcall=0.2.0=pyh9f0ad1d_0
  - backports=1.0=py_2
  - backports.functools_lru_cache=1.6.4=pyhd8ed1ab_0
  - binutils_impl_linux-64=2.35.1=h193b22a_2
  - binutils_linux-64=2.35=h67ddf6f_30
  - bleach=3.3.0=pyh44b312d_0
  - brotlipy=0.7.0=py39h3811e60_1001
  - bwidget=1.9.14=ha770c72_0
  - bzip2=1.0.8=h7f98852_4
  - c-ares=1.17.1=h7f98852_1
  - ca-certificates=2020.12.5=ha878542_0
  - cairo=1.16.0=h6cf1ce9_1008
  - certifi=2020.12.5=py39hf3d152e_1
  - cffi=1.14.5=py39he32792d_0
  - chardet=4.0.0=py39hf3d152e_1
  - cryptography=3.4.7=py39hbca0aa6_0
  - curl=7.76.1=hea6ffbf_2
  - decorator=5.0.9=pyhd8ed1ab_0
  - defusedxml=0.7.1=pyhd8ed1ab_0
  - entrypoints=0.3=pyhd8ed1ab_1003
  - font-ttf-dejavu-sans-mono=2.37=hab24e00_0
  - font-ttf-inconsolata=3.000=h77eed37_0
  - font-ttf-source-code-pro=2.038=h77eed37_0
  - font-ttf-ubuntu=0.83=hab24e00_0
  - fontconfig=2.13.1=hba837de_1005
  - fonts-conda-ecosystem=1=0
  - fonts-conda-forge=1=0
  - freetype=2.10.4=h0708190_1
  - fribidi=1.0.10=h36c2ea0_0
  - gcc_impl_linux-64=9.3.0=h70c0ae5_19
  - gcc_linux-64=9.3.0=hf25ea35_30
  - gettext=0.19.8.1=h0b5b191_1005
  - gfortran_impl_linux-64=9.3.0=hc4a2995_19
  - gfortran_linux-64=9.3.0=hdc58fab_30
  - graphite2=1.3.13=h58526e2_1001
  - gsl=2.6=he838d99_2
  - gxx_impl_linux-64=9.3.0=hd87eabc_19
  - gxx_linux-64=9.3.0=h3fbe746_30
  - harfbuzz=2.8.1=h83ec7ef_0
  - icu=68.1=h58526e2_0
  - idna=2.10=pyh9f0ad1d_0
  - importlib-metadata=4.0.1=py39hf3d152e_0
  - ipykernel=5.5.5=py39hef51801_0
  - ipython=7.23.1=py39hef51801_0
  - ipython_genutils=0.2.0=py_1
  - jbig=2.1=h7f98852_2003
  - jedi=0.18.0=py39hf3d152e_2
  - jinja2=3.0.1=pyhd8ed1ab_0
  - jpeg=9d=h36c2ea0_0
  - json5=0.9.5=pyh9f0ad1d_0
  - jsonschema=3.2.0=pyhd8ed1ab_3
  - jupyter_client=6.1.12=pyhd8ed1ab_0
  - jupyter_core=4.7.1=py39hf3d152e_0
  - jupyter_server=1.8.0=pyhd8ed1ab_0
  - jupyterlab=3.0.16=pyhd8ed1ab_0
  - jupyterlab_pygments=0.1.2=pyh9f0ad1d_0
  - jupyterlab_server=2.5.2=pyhd8ed1ab_0
  - kernel-headers_linux-64=2.6.32=h77966d4_13
  - krb5=1.19.1=hcc1bbae_0
  - ld_impl_linux-64=2.35.1=hea4e1c9_2
  - lerc=2.2.1=h9c3ff4c_0
  - libarchive=3.5.1=hccf745f_2
  - libblas=3.9.0=9_openblas
  - libcblas=3.9.0=9_openblas
  - libcurl=7.76.1=h2574ce0_2
  - libdeflate=1.7=h7f98852_5
  - libedit=3.1.20191231=he28a2e2_2
  - libev=4.33=h516909a_1
  - libffi=3.3=h58526e2_2
  - libgcc-devel_linux-64=9.3.0=h7864c58_19
  - libgcc-ng=9.3.0=h2828fa1_19
  - libgfortran-ng=9.3.0=hff62375_19
  - libgfortran5=9.3.0=hff62375_19
  - libglib=2.68.2=h3e27bee_0
  - libgomp=9.3.0=h2828fa1_19
  - libiconv=1.16=h516909a_0
  - liblapack=3.9.0=9_openblas
  - libmamba=0.13.1=h3a044de_0
  - libnghttp2=1.43.0=h812cca2_0
  - libopenblas=0.3.15=pthreads_h8fe5266_1
  - libpng=1.6.37=h21135ba_2
  - libsodium=1.0.18=h36c2ea0_1
  - libsolv=0.7.18=h780b84a_0
  - libssh2=1.9.0=ha56f1ee_6
  - libstdcxx-devel_linux-64=9.3.0=hb016644_19
  - libstdcxx-ng=9.3.0=h6de172a_19
  - libtiff=4.3.0=hf544144_1
  - libuuid=2.32.1=h7f98852_1000
  - libwebp-base=1.2.0=h7f98852_2
  - libxcb=1.13=h7f98852_1003
  - libxml2=2.9.12=h72842e0_0
  - lz4-c=1.9.3=h9c3ff4c_0
  - lzo=2.10=h516909a_1000
  - make=4.3=hd18ef5c_1
  - markupsafe=2.0.1=py39h3811e60_0
  - matplotlib-inline=0.1.2=pyhd8ed1ab_2
  - mistune=0.8.4=py39h3811e60_1003
  - nbclassic=0.3.1=pyhd8ed1ab_1
  - nbclient=0.5.3=pyhd8ed1ab_0
  - nbconvert=6.0.7=py39hf3d152e_3
  - nbformat=5.1.3=pyhd8ed1ab_0
  - ncurses=6.2=h58526e2_4
  - nest-asyncio=1.5.1=pyhd8ed1ab_0
  - notebook=6.4.0=pyha770c72_0
  - openssl=1.1.1k=h7f98852_0
  - packaging=20.9=pyh44b312d_0
  - pandoc=2.13=h7f98852_0
  - pandocfilters=1.4.2=py_1
  - pango=1.48.5=hb8ff022_0
  - parso=0.8.2=pyhd8ed1ab_0
  - pcre=8.44=he1b5a44_0
  - pcre2=10.36=h032f7d1_1
  - pexpect=4.8.0=pyh9f0ad1d_2
  - pickleshare=0.7.5=py_1003
  - pip=21.1.2=pyhd8ed1ab_0
  - pixman=0.40.0=h36c2ea0_0
  - prometheus_client=0.10.1=pyhd8ed1ab_0
  - prompt-toolkit=3.0.18=pyha770c72_0
  - pthread-stubs=0.4=h36c2ea0_1001
  - ptyprocess=0.7.0=pyhd3deb0d_0
  - pycparser=2.20=pyh9f0ad1d_2
  - pygments=2.9.0=pyhd8ed1ab_0
  - pyopenssl=20.0.1=pyhd8ed1ab_0
  - pyparsing=2.4.7=pyh9f0ad1d_0
  - pyrsistent=0.17.3=py39h3811e60_2
  - pysocks=1.7.1=py39hf3d152e_3
  - python=3.9.4=hffdb5ce_0_cpython
  - python-dateutil=2.8.1=py_0
  - python_abi=3.9=1_cp39
  - pytz=2021.1=pyhd8ed1ab_0
  - pyzmq=22.0.3=py39h37b5a0c_1
  - r-askpass=1.1=r40hcfec24a_2
  - r-assertthat=0.2.1=r40hc72bb7e_2
  - r-base=4.0.5=h9e01966_1
  - r-base64enc=0.1_3=r40hcfec24a_1004
  - r-callr=3.7.0=r40hc72bb7e_0
  - r-cli=2.5.0=r40hc72bb7e_0
  - r-colorspace=2.0_1=r40hcfec24a_0
  - r-cpp11=0.2.7=r40hc72bb7e_0
  - r-crayon=1.4.1=r40hc72bb7e_0
  - r-curl=4.3.1=r40hcfec24a_0
  - r-digest=0.6.27=r40h03ef668_0
  - r-ellipsis=0.3.2=r40hcfec24a_0
  - r-evaluate=0.14=r40hc72bb7e_2
  - r-fansi=0.5.0=r40hcfec24a_0
  - r-farver=2.1.0=r40h03ef668_0
  - r-gdtools=0.2.2=r40h36050f4_1
  - r-glue=1.4.2=r40hcfec24a_0
  - r-highr=0.9=r40hc72bb7e_0
  - r-htmltools=0.5.1.1=r40h03ef668_0
  - r-httr=1.4.2=r40hc72bb7e_0
  - r-irdisplay=1.0=r40hd8ed1ab_0
  - r-irkernel=1.2=r40hc72bb7e_0
  - r-jsonlite=1.7.2=r40hcfec24a_0
  - r-kableextra=1.3.4=r40hc72bb7e_0
  - r-knitr=1.33=r40hc72bb7e_0
  - r-labeling=0.4.2=r40hc72bb7e_0
  - r-lifecycle=1.0.0=r40hc72bb7e_0
  - r-magrittr=2.0.1=r40hcfec24a_1
  - r-markdown=1.1=r40hcfec24a_1
  - r-mime=0.10=r40hcfec24a_0
  - r-munsell=0.5.0=r40hc72bb7e_1003
  - r-openssl=1.4.4=r40he36bf35_0
  - r-pbdzmq=0.3_5=r40h42bf92c_1
  - r-pillar=1.6.1=r40hc72bb7e_0
  - r-pkgconfig=2.0.3=r40hc72bb7e_1
  - r-processx=3.5.2=r40hcfec24a_0
  - r-ps=1.6.0=r40hcfec24a_0
  - r-r6=2.5.0=r40hc72bb7e_0
  - r-rcolorbrewer=1.1_2=r40h785f33e_1003
  - r-rcpp=1.0.6=r40h03ef668_0
  - r-repr=1.1.3=r40h785f33e_0
  - r-rlang=0.4.11=r40hcfec24a_0
  - r-rmarkdown=2.8=r40hc72bb7e_0
  - r-rstudioapi=0.13=r40hc72bb7e_0
  - r-rvest=1.0.0=r40hc72bb7e_0
  - r-scales=1.1.1=r40hc72bb7e_0
  - r-selectr=0.4_2=r40hc72bb7e_1
  - r-stringi=1.6.2=r40hcabe038_0
  - r-stringr=1.4.0=r40hc72bb7e_2
  - r-svglite=2.0.0=r40h03ef668_0
  - r-sys=3.4=r40hcfec24a_0
  - r-systemfonts=1.0.2=r40hef9c87a_0
  - r-tibble=3.1.2=r40hcfec24a_0
  - r-tinytex=0.31=r40hc72bb7e_0
  - r-utf8=1.2.1=r40hcfec24a_0
  - r-uuid=0.1_4=r40hcfec24a_1
  - r-vctrs=0.3.8=r40hcfec24a_1
  - r-viridislite=0.4.0=r40hc72bb7e_0
  - r-webshot=0.5.2=r40hc72bb7e_1
  - r-xfun=0.23=r40hcfec24a_0
  - r-xml2=1.3.2=r40h03ef668_1
  - r-yaml=2.2.1=r40hcfec24a_1
  - readline=8.1=h46c0cb4_0
  - reproc=14.2.1=h36c2ea0_0
  - reproc-cpp=14.2.1=h58526e2_0
  - requests=2.25.1=pyhd3deb0d_0
  - rhumba=0.1.1=r40h9c3ff4c_4
  - sed=4.8=he412f7d_0
  - send2trash=1.5.0=py_0
  - setuptools=49.6.0=py39hf3d152e_3
  - six=1.16.0=pyh6c4a22f_0
  - sniffio=1.2.0=py39hf3d152e_1
  - sqlite=3.35.5=h74cdb3f_0
  - sysroot_linux-64=2.12=h77966d4_13
  - terminado=0.10.0=py39hf3d152e_0
  - testpath=0.5.0=pyhd8ed1ab_0
  - tk=8.6.10=h21135ba_1
  - tktable=2.10=hb7b940f_3
  - tornado=6.1=py39h3811e60_1
  - traitlets=5.0.5=py_0
  - tzdata=2021a=he74cb21_0
  - urllib3=1.26.4=pyhd8ed1ab_0
  - wcwidth=0.2.5=pyh9f0ad1d_2
  - webencodings=0.5.1=py_1
  - websocket-client=0.57.0=py39hf3d152e_4
  - wheel=0.36.2=pyhd3deb0d_0
  - xorg-kbproto=1.0.7=h7f98852_1002
  - xorg-libice=1.0.10=h7f98852_0
  - xorg-libsm=1.2.3=hd9c2040_1000
  - xorg-libx11=1.7.1=h7f98852_0
  - xorg-libxau=1.0.9=h7f98852_0
  - xorg-libxdmcp=1.1.3=h7f98852_0
  - xorg-libxext=1.3.4=h7f98852_1
  - xorg-libxrender=0.9.10=h7f98852_1003
  - xorg-libxt=1.2.1=h7f98852_2
  - xorg-renderproto=0.11.1=h7f98852_1002
  - xorg-xextproto=7.3.0=h7f98852_1002
  - xorg-xproto=7.0.31=h7f98852_1007
  - xz=5.2.5=h516909a_1
  - yaml-cpp=0.6.3=he1b5a44_4
  - zeromq=4.3.4=h9c3ff4c_0
  - zipp=3.4.1=pyhd8ed1ab_0
  - zlib=1.2.11=h516909a_1010
  - zstd=1.5.0=ha95c52a_0

I have
image

@sjgenco
Copy link
Author

sjgenco commented May 26, 2021

Thanks for the reply. As I said in my post, the head() command is not the problem. I get the same default result you do, in both JupyterLab and RStudio. The problem is in the next block of code, using the kable_styling function (or any other kable formatting function). It simply outputs the html code rather than evaluating it.

To reproduce, run this code snippet (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.

@agoose77
Copy link
Contributor

Ah, drat - I didn't read your post properly! Thanks for the clarification.

I don't have time to look at this right now, but I have some thoughts. Although I'm not an R user, it's clear that the rich display mechanism works for the original table. This leads me to suspect that it's something about the kbl() knitr result that isn't rich renderable. That will be something that the knitr authors (or perhaps IRKernel, but unlikely) need to address. Someone with more R knowledge can probably dig in and find where these two differ.

@sjgenco
Copy link
Author

sjgenco commented May 26, 2021

Thanks Angus. I've cross-posted this over on the KableExtras issues page (haozhu233/kableExtra#620 (comment)).
They may have some ideas as well.

@agoose77
Copy link
Contributor

@sjgenco RE the xelatex error, are you running the nbconvert command in the same conda environment as JupyterLab is running?

@sjgenco
Copy link
Author

sjgenco commented May 27, 2021

Here the list of packages currently in my conda virtual env, r_env. nbconvert is in there, as is pandoc.
My R version is 3.6.1 btw, in case that might be relevant.

Environment:
r_env) xxxxxxxx@x86_64-apple-darwin13 ~ % conda list
# packages in environment at /Users/xxxxxxxx/opt/anaconda3/envs/r_env:
#
# Name                    Version                   Build  Channel
_r-mutex                  1.0.0               anacondar_1  
anyio                     2.2.0            py38hecd8cb5_1  
appnope                   0.1.2           py38hecd8cb5_1001  
argon2-cffi               20.1.0           py38h9ed2024_1  
async_generator           1.10               pyhd3eb1b0_0  
attrs                     21.2.0             pyhd3eb1b0_0  
babel                     2.9.1              pyhd3eb1b0_0  
backcall                  0.2.0              pyhd3eb1b0_0  
bleach                    3.3.0              pyhd3eb1b0_0  
brotlipy                  0.7.0           py38h9ed2024_1003  
bwidget                   1.9.11                        1  
bzip2                     1.0.8                h1de35cc_0  
ca-certificates           2021.4.13            hecd8cb5_1  
cairo                     1.14.12              hc4e6be7_4  
cctools                   927.0.2              h5ba7a2e_4  
certifi                   2020.12.5        py38hecd8cb5_0  
cffi                      1.14.0           py38hb5b8e2f_0  
chardet                   4.0.0           py38hecd8cb5_1003  
clang                     10.0.0          default_hf57f61e_0  
clang_osx-64              10.0.0               h05bbb7f_0  
clangxx                   10.0.0          default_hf57f61e_0  
clangxx_osx-64            10.0.0               h05bbb7f_1  
compiler-rt               10.0.0               h47ead80_0  
compiler-rt_osx-64        10.0.0               hbcc88fd_0  
cryptography              3.4.7            py38h2fd3fbb_0  
curl                      7.67.0               ha441bb4_0  
decorator                 5.0.7              pyhd3eb1b0_0  
defusedxml                0.7.1              pyhd3eb1b0_0  
entrypoints               0.3                      py38_0  
font-ttf-dejavu-sans-mono 2.37                 h6964260_0  
font-ttf-inconsolata      2.001                hcb22688_0  
font-ttf-source-code-pro  2.030                h7457263_0  
font-ttf-ubuntu           0.83                 h8b1ccd4_0  
fontconfig                2.13.1               ha9ee91d_0  
fonts-anaconda            1                    h8fa9717_0  
freetype                  2.10.4               ha233b18_0  
fribidi                   1.0.10               haf1e3a3_0  
gettext                   0.21.0               h7535e17_0  
gfortran_osx-64           4.8.5                h22b1bf0_8  
glib                      2.63.1               hd977a24_0  
graphite2                 1.3.14               h38d11af_0  
gsl                       2.4                  h1de35cc_4  
harfbuzz                  2.4.0                h831d699_0  
icu                       58.2                 h0a44026_3  
idna                      2.10               pyhd3eb1b0_0  
importlib-metadata        3.10.0           py38hecd8cb5_0  
importlib_metadata        3.10.0               hd3eb1b0_0  
ipykernel                 5.3.4            py38h5ca1d4c_0  
ipython                   7.22.0           py38h01d92e1_0  
ipython_genutils          0.2.0              pyhd3eb1b0_1  
jedi                      0.17.0                   py38_0  
jinja2                    2.11.3             pyhd3eb1b0_0  
jpeg                      9b                   he5867d9_2  
json5                     0.9.5                      py_0  
jsonschema                3.2.0                      py_2  
jupyter-packaging         0.7.12             pyhd3eb1b0_0  
jupyter_client            6.1.12             pyhd3eb1b0_0  
jupyter_core              4.7.1            py38hecd8cb5_0  
jupyter_server            1.4.1            py38hecd8cb5_0  
jupyterlab                3.0.14             pyhd3eb1b0_1  
jupyterlab_pygments       0.1.2                      py_0  
jupyterlab_server         2.4.0              pyhd3eb1b0_0  
krb5                      1.16.4               hddcf347_0  
latest                    0.6.0                    pypi_0    pypi
ld64                      450.3                h3c32e8a_4  
libcurl                   7.67.0               h051b688_0  
libcxx                    10.0.0                        1  
libedit                   3.1.20210216         h9ed2024_1  
libffi                    3.2.1             h0a44026_1007  
libgfortran               3.0.1                h93005f0_2  
libiconv                  1.16                 h1de35cc_0  
libllvm10                 10.0.1               h76017ad_5  
libpng                    1.6.37               ha441bb4_0  
libsodium                 1.0.18               h1de35cc_0  
libssh2                   1.9.0                ha12b0ac_1  
libtiff                   4.1.0                hcb84e12_1  
libxml2                   2.9.10               h7cdb67c_3  
llvm-openmp               10.0.0               h28b9765_0  
lz4-c                     1.9.3                h23ab428_0  
make                      4.2.1                h3efe00b_1  
markupsafe                1.1.1            py38h1de35cc_1  
mistune                   0.8.4           py38h1de35cc_1001  
nbclassic                 0.2.6              pyhd3eb1b0_0  
nbclient                  0.5.3              pyhd3eb1b0_0  
nbconvert                 6.0.7                    py38_0  
nbformat                  5.1.3              pyhd3eb1b0_0  
nbresuse                  0.4.0              pyhd8ed1ab_0    conda-forge
ncurses                   6.2                  h0a44026_1  
nest-asyncio              1.5.1              pyhd3eb1b0_0  
nodejs                    0.1.1                    pypi_0    pypi
notebook                  6.3.0            py38hecd8cb5_0  
openjdk                   11.0.6               h7bc2e8c_1  
openssl                   1.1.1k               h9ed2024_0  
optional-django           0.1.0                    pypi_0    pypi
packaging                 20.9               pyhd3eb1b0_0  
pandoc                    2.12                 hecd8cb5_0  
pandocfilters             1.4.3            py38hecd8cb5_1  
pango                     1.42.4               hc249df1_1  
parso                     0.8.2              pyhd3eb1b0_0  
pcre                      8.44                 hb1e8313_0  
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5           pyhd3eb1b0_1003  
pip                       21.0.1           py38hecd8cb5_0  
pixman                    0.40.0               haf1e3a3_0  
prometheus_client         0.10.1             pyhd3eb1b0_0  
prompt-toolkit            3.0.17             pyh06a4308_0  
psutil                    5.8.0            py38h9ed2024_1  
ptyprocess                0.7.0              pyhd3eb1b0_2  
pycparser                 2.20                       py_2  
pygments                  2.8.1              pyhd3eb1b0_0  
pyopenssl                 20.0.1             pyhd3eb1b0_1  
pyparsing                 2.4.7              pyhd3eb1b0_0  
pyrsistent                0.17.3           py38haf1e3a3_0  
pysocks                   1.7.1                    py38_1  
python                    3.8.2                hfe9666f_0  
python-dateutil           2.8.1              pyhd3eb1b0_0  
pytz                      2021.1             pyhd3eb1b0_0  
pyyaml                    5.4.1                    pypi_0    pypi
pyzmq                     20.0.0           py38h23ab428_1  
r-askpass                 1.0               r36h1de35cc_0  
r-assertthat              0.2.1             r36h6115d3f_0  
r-backports               1.1.4             r36h46e59ec_0  
r-base                    3.6.1                hcb44179_1  
r-base64enc               0.1_3             r36h46e59ec_4  
r-bh                      1.69.0_1          r36h6115d3f_0  
r-bit                     1.1_14            r36h46e59ec_0  
r-bit64                   0.9_7             r36h46e59ec_0  
r-bitops                  1.0_6             r36h46e59ec_4  
r-blob                    1.1.1             r36h6115d3f_0  
r-boot                    1.3_20            r36h6115d3f_0  
r-broom                   0.5.2             r36h6115d3f_0  
r-callr                   3.2.0             r36h6115d3f_0  
r-caret                   6.0_83            r36h46e59ec_0  
r-catools                 1.17.1.2          r36h466af19_0  
r-cellranger              1.1.0             r36h6115d3f_0  
r-class                   7.3_15            r36h46e59ec_0  
r-cli                     1.1.0             r36h6115d3f_0  
r-clipr                   0.6.0             r36h6115d3f_0  
r-cluster                 2.0.8             r36hfffe0aa_0  
r-codetools               0.2_16            r36h6115d3f_0  
r-colorspace              1.4_1             r36h46e59ec_0  
r-config                  0.3               r36h6115d3f_0  
r-crayon                  1.3.4             r36h6115d3f_0  
r-curl                    3.3               r36h46e59ec_0  
r-data.table              1.12.2            r36h46e59ec_0  
r-dbi                     1.0.0             r36h6115d3f_0  
r-dbplyr                  1.4.0             r36h6115d3f_0  
r-dichromat               2.0_0             r36h6115d3f_4  
r-digest                  0.6.18            r36h46e59ec_0  
r-dplyr                   0.8.0.1           r36h466af19_0  
r-ellipsis                0.1.0             r36h46e59ec_0  
r-essentials              3.6.0                     r36_0  
r-evaluate                0.13              r36h6115d3f_0  
r-fansi                   0.4.0             r36h46e59ec_0  
r-forcats                 0.4.0             r36h6115d3f_0  
r-foreach                 1.4.4             r36h6115d3f_0  
r-foreign                 0.8_71            r36h46e59ec_0  
r-forge                   0.2.0             r36h6115d3f_0  
r-formatr                 1.6               r36h6115d3f_0  
r-fs                      1.2.7             r36h466af19_0  
r-generics                0.0.2             r36h6115d3f_0  
r-ggplot2                 3.1.1             r36h6115d3f_0  
r-glmnet                  2.0_16            r36hfffe0aa_0  
r-glue                    1.3.1             r36h46e59ec_0  
r-gower                   0.2.0             r36h46e59ec_0  
r-gtable                  0.3.0             r36h6115d3f_0  
r-haven                   2.1.0             r36h466af19_0  
r-hexbin                  1.27.2            r36hfffe0aa_0  
r-highr                   0.8               r36h6115d3f_0  
r-hms                     0.4.2             r36h6115d3f_0  
r-htmltools               0.3.6             r36h466af19_0  
r-htmlwidgets             1.3               r36h6115d3f_0  
r-httpuv                  1.5.1             r36h466af19_0  
r-httr                    1.4.0             r36h6115d3f_0  
r-ipred                   0.9_8             r36h46e59ec_0  
r-irdisplay               0.7.0             r36h6115d3f_0  
r-irkernel                0.8.15                    r36_0    r
r-iterators               1.0.10            r36h6115d3f_0  
r-jsonlite                1.6               r36h46e59ec_0  
r-kernsmooth              2.23_15           r36hfffe0aa_4  
r-knitr                   1.22              r36h6115d3f_0  
r-labeling                0.3               r36h6115d3f_4  
r-later                   0.8.0             r36h466af19_0  
r-lattice                 0.20_38           r36h46e59ec_0  
r-lava                    1.6.5             r36h6115d3f_0  
r-lazyeval                0.2.2             r36h46e59ec_0  
r-lubridate               1.7.4             r36h466af19_0  
r-magrittr                1.5               r36h6115d3f_4  
r-maps                    3.3.0             r36h46e59ec_0  
r-markdown                0.9               r36h46e59ec_0  
r-mass                    7.3_51.3          r36h46e59ec_0  
r-matrix                  1.2_17            r36h46e59ec_0  
r-mgcv                    1.8_28            r36h46e59ec_0  
r-mime                    0.6               r36h46e59ec_0  
r-miniui                  0.1.1.1           r36h6115d3f_0  
r-modelmetrics            1.2.2             r36h466af19_0  
r-modelr                  0.1.4             r36h6115d3f_0  
r-mongolite               2.0.1             r36h46e59ec_0  
r-munsell                 0.5.0             r36h6115d3f_0  
r-nlme                    3.1_139           r36hfffe0aa_0  
r-nnet                    7.3_12            r36h46e59ec_0  
r-numderiv                2016.8_1          r36h6115d3f_0  
r-odbc                    1.1.5             r36h0a44026_0  
r-openssl                 1.3               r36h46e59ec_0  
r-packrat                 0.5.0             r36h6115d3f_0  
r-pbdzmq                  0.3_3             r36hcccc9c6_1  
r-pillar                  1.3.1             r36h6115d3f_0  
r-pkgconfig               2.0.2             r36h6115d3f_0  
r-pki                     0.1_5.1           r36h46e59ec_1  
r-plogr                   0.2.0             r36h6115d3f_0  
r-plyr                    1.8.4             r36h466af19_0  
r-prettyunits             1.0.2             r36h6115d3f_0  
r-processx                3.3.0             r36h46e59ec_0  
r-prodlim                 2018.04.18        r36h466af19_0  
r-profvis                 0.3.5             r36h46e59ec_0  
r-progress                1.2.0             r36h6115d3f_0  
r-promises                1.0.1             r36h466af19_0  
r-ps                      1.3.0             r36h46e59ec_0  
r-purrr                   0.3.2             r36h46e59ec_0  
r-quantmod                0.4_14            r36h6115d3f_0  
r-r2d3                    0.2.3             r36h6115d3f_0  
r-r6                      2.4.0             r36h6115d3f_0  
r-randomforest            4.6_14            r36hfffe0aa_0  
r-rappdirs                0.3.1             r36h46e59ec_0  
r-rbokeh                  0.6.3                     r36_0  
r-rcolorbrewer            1.1_2             r36h6115d3f_0  
r-rcpp                    1.0.1             r36h466af19_0  
r-rcpproll                0.3.0             r36h466af19_0  
r-rcurl                   1.95_4.12         r36h46e59ec_0  
r-readr                   1.3.1             r36h466af19_0  
r-readxl                  1.3.1             r36h466af19_0  
r-recipes                 0.1.5             r36h6115d3f_0  
r-recommended             3.6.0                     r36_0  
r-rematch                 1.0.1             r36h6115d3f_0  
r-repr                    0.19.2            r36h6115d3f_0  
r-reprex                  0.2.1             r36h6115d3f_0  
r-reshape2                1.4.3             r36h466af19_0  
r-rjava                   0.9_11            r36h46e59ec_0  
r-rjdbc                   0.2_7.1           r36h6115d3f_0  
r-rjsonio                 1.3_1.1           r36h466af19_0  
r-rlang                   0.3.4             r36h46e59ec_0  
r-rmarkdown               1.12              r36h6115d3f_0  
r-rpart                   4.1_15            r36h46e59ec_0  
r-rprojroot               1.3_2             r36h6115d3f_0  
r-rsconnect               0.8.13            r36h6115d3f_0  
r-rstudioapi              0.10              r36h6115d3f_0  
r-rvest                   0.3.3             r36h6115d3f_0  
r-scales                  1.0.0             r36h466af19_0  
r-selectr                 0.4_1             r36h6115d3f_0  
r-shiny                   1.3.2             r36h6115d3f_0  
r-sourcetools             0.1.7             r36h466af19_0  
r-sparklyr                1.0.0             r36h6115d3f_0  
r-spatial                 7.3_11            r36h46e59ec_4  
r-squarem                 2017.10_1         r36h6115d3f_0  
r-stringi                 1.4.3             r36h466af19_0  
r-stringr                 1.4.0             r36h6115d3f_0  
r-survival                2.44_1.1          r36h46e59ec_0  
r-sys                     3.2               r36h46e59ec_0  
r-tibble                  2.1.1             r36h46e59ec_0  
r-tidyr                   0.8.3             r36h466af19_0  
r-tidyselect              0.2.5             r36h466af19_0  
r-tidyverse               1.2.1             r36h6115d3f_0  
r-timedate                3043.102          r36h6115d3f_0  
r-tinytex                 0.12              r36h6115d3f_0  
r-ttr                     0.23_4            r36hfffe0aa_0  
r-utf8                    1.1.4             r36h46e59ec_0  
r-uuid                    0.1_2             r36h46e59ec_4  
r-viridislite             0.3.0             r36h6115d3f_0  
r-whisker                 0.3_2             r36h6115d3f_4  
r-withr                   2.1.2             r36h6115d3f_0  
r-xfun                    0.6               r36h6115d3f_0  
r-xml2                    1.2.0             r36h466af19_0  
r-xtable                  1.8_4             r36h6115d3f_0  
r-xts                     0.11_2            r36h46e59ec_0  
r-yaml                    2.2.0             r36h46e59ec_0  
r-zoo                     1.8_6             r36h46e59ec_0  
readline                  7.0                  h1de35cc_5  
requests                  2.25.1             pyhd3eb1b0_0  
rstudio                   1.1.456              h04f5b5a_1  
send2trash                1.5.0              pyhd3eb1b0_1  
setuptools                52.0.0           py38hecd8cb5_0  
six                       1.15.0           py38hecd8cb5_0  
sniffio                   1.2.0            py38hecd8cb5_1  
sqlite                    3.33.0               hffcf06c_0  
tapi                      1000.10.8            ha1b3eb9_0  
terminado                 0.9.4            py38hecd8cb5_0  
testpath                  0.4.4              pyhd3eb1b0_0  
tk                        8.6.10               hb0a8c7a_0  
tktable                   2.10                 h1de35cc_0  
tornado                   6.1              py38h9ed2024_0  
traitlets                 5.0.5              pyhd3eb1b0_0  
unixodbc                  2.3.9                haf1e3a3_0  
urllib3                   1.26.4             pyhd3eb1b0_0  
wcwidth                   0.2.5                      py_0  
webencodings              0.5.1                    py38_1  
wheel                     0.36.2             pyhd3eb1b0_0  
xz                        5.2.5                h1de35cc_0  
yarn                      0.25.2               hd3eb1b0_1  
zeromq                    4.3.4                h23ab428_0  
zipp                      3.4.1              pyhd3eb1b0_0  
zlib                      1.2.11               h1de35cc_3  
zstd                      1.4.9                h322a384_0  

@agoose77
Copy link
Contributor

agoose77 commented May 28, 2021

@sjgenco the code that raises that error is relatively simple; it calls shutil.which to test for the LaTeX command (xelatex). If it raises an OSError because it cannot find xelatex, then it strongly suggests that xelatex isn't on your PATH. Is it possible that the environment that launches nbconvert / jupyterlab is not the same as the one that you're testing in the shell? Otherwise, what is the result of

command -v /Library/TeX/texbin/xelatex

and

command -v xelatex

@sjgenco
Copy link
Author

sjgenco commented May 28, 2021

Hmm. Good to learn you've found the source, but the reason for the OSError remains a mystery. Here are the results for your suggested commands, and a couple of others:

(r_env) sjgenco@x86_64-apple-darwin13 ~ % where xelatex                         
/Library/TeX/texbin/xelatex

(r_env) sjgenco@x86_64-apple-darwin13 ~ % echo $PATH                            
/Users/sjgenco/opt/anaconda3/envs/r_env/bin:     <-- I've put these on separate lines here
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/Library/TeX/texbin:
/opt/X11/bin:
/Users/sjgenco/opt/anaconda3/bin:
/Users/sjgenco/opt/anaconda3/condabin

(r_env) sjgenco@x86_64-apple-darwin13 ~ % command -v xelatex
/Library/TeX/texbin/xelatex

(r_env) sjgenco@x86_64-apple-darwin13 ~ % command -v /Library/TeX/texbin/xelatex
/Library/TeX/texbin/xelatex

(r_env) sjgenco@x86_64-apple-darwin13 ~ % 

I wonder if this might be relevant. I looked up shutil.which and see it's a python utility function, so I ran a couple of python commands with it.

import os
import shutil
shutil.which("python")
'/Users/xxxxxxxx/opt/anaconda3/envs/r_env/bin/python'

But when I do shutil.which("xelatex") or shutil.which("Tex") I get no response.

Then I tried this:

import sys
for p in sys.path:
    print(p)
/Users/xxxxxxxx/Dropbox/R/R ANES
/Users/xxxxxxxx/opt/anaconda3/envs/r_env/lib/python38.zip
/Users/xxxxxxxx/opt/anaconda3/envs/r_env/lib/python3.8
/Users/xxxxxxxx/opt/anaconda3/envs/r_env/lib/python3.8/lib-dynload

/Users/xxxxxxxx/.local/lib/python3.8/site-packages
/Users/xxxxxxxx/opt/anaconda3/envs/r_env/lib/python3.8/site-packages
/Users/xxxxxxxx/opt/anaconda3/envs/r_env/lib/python3.8/site-packages/IPython/extensions
/Users/xxxxxxxx/.ipython

Tex and xelatex aren't on this path, so maybe that's the problem?
So I tried appending the folder with xelatex in it (/Library/TeX/texbin) to the path with

sys.path.append("/Library/TeX/texbin")

At first it appears in the path, as expected, but then it disappears again when I restart the kernel.

My guess is this has something to do with this python path. Will dig some more.

@agoose77
Copy link
Contributor

agoose77 commented May 28, 2021

sys.path is the python module search path. xelatex needs to be on the system search path, I.e os.environ['PATH']. It's odd that you get this error if you launch Jupyter Lab from the same shell.

@sjgenco
Copy link
Author

sjgenco commented May 28, 2021

Well, it's not there ...

os.environ['PATH'].split(':')
['/Users/xxxxxxxx/opt/anaconda3/envs/r_env/bin',
 '/Users/xxxxxxxx/opt/anaconda3/condabin',
 '/usr/bin',
 '/bin',
 '/usr/sbin',
 '/sbin']

but this "PATH" is different from $PATH, which has a bunch more folders, including the xelatex folder:

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

Arghh ... path, PATH, PYTHONPATH ... there are too many paths in this forest

@sjgenco
Copy link
Author

sjgenco commented May 28, 2021

Here's another interesting discrepancy that may be relevant. As we all know, the 'export to PDF' command doesn't work inside JupyterLab, but it does work at the command line with something like
jupyter nbconvert --to pdf "Dropbox/R/R ANES/ANES2020.ipynb"
(the "pattern" has to start with the folder beneath your home folder (on Mac, that's under HD/Users/username/)

I also sent this issue to the kableExtra folks on github and they suggested a workaround which I tried out in a fresh JupyterLab Notebook. The workaround worked in that it produced a nicely formatted inline table. Just now, I ran the command-line nbconvert command to export that notebook to 2 docs, one a pdf doc and the other an html doc. The interesting part is that the inline html output was correctly rendered as a formatted table in the exported html file. Here's a snippet:
t1

But the pdf conversion just skipped over that output.
t2

I don't believe the html export invokes latex. It's clear from the formatting that the pdf export does. So this shows all the basic machinery for converting jupyterlab notebooks is present. But whatever is keeping JupyterLab from outputing kable-formatted text inline, it's also causing it to fail to print it as part of a full document export.

BTW: that workaround is described here: https://stackoverflow.com/questions/46531571/how-do-i-format-an-r-table-in-an-r-jupyter-notebook/46532394#46532394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants