Reticulate no display error when knitting rmarkdown


Using a rstudio in a docker container (ml-verse) from my home server. When using python in an rmarkdown doc I get an error saying I have no display when trying to knit a matplotlib graph. The plot shows fine inline

import matplotlib.pyplot as plt

X = [1,2,3,4,5]
Y= [2,6,13,4,3]


Quitting from lines 13-22 (temp.Rmd) 
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  TclError: couldn't connect to display ":0"

Detailed traceback:
  File "<string>", line 1, in <module>
  File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/matplotlib/", line 2890, in scatter
    __ret = gca().scatter(
  File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/matplotlib/", line 2368, in gca
    return gcf().gca(**kwargs)
  File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/matplotlib/", line 747, in gcf
    return figure()
  File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/matplotlib/", line 693, in figure
  File "/home/rstudio/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/matplotlib/", line 315, in new_figure_manager
    return _backend_mod.new_figure_manager(*args, **kwargs)
  File "/home/rstudio/.local/share/r-miniconda/
Calls: <Anonymous> ... py_capture_output -> force -> <Anonymous> -> py_call_impl
Execution halted

Ok I figured it out

You need to use

import matplotlib

where X is Agg (for PNGs), PDF, SVG or PS

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.