5

I am using R in Jupyter, but unable to plot graphs in the notebook itself.

Here is a reproducible example

set.seed(123)
mat = as.matrix(x = rnorm(100), y = rnorm(100))
plot(mat)

In Jupyter:

Error in png(tf, width, height, "in", pointsize, bg, res, antialias = antialias): unable to start png() device
Traceback:

If I use following, I can save the image in png format in current working directory.

png('test.png')
plot(mat)
dev.off()

Edit:

SessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

I have gone through following but none of them solve my problem.

  1. Displaying ggplot2 graphs from R in Jupyter
  2. unable to plot in jupyter notebook using R kernel
  3. libXrender.so.1 is required to display R plots inline
  4. Can't display png
  5. Rendering of graphs in R kernel Notebooks on GitHub (relevant to Github)
Gaurav Singhal
  • 998
  • 2
  • 10
  • 25
  • since I could not got this to work, I shifted to R markdown which is easier to work with R studio and provides a lot more flexibility. I am kind of grateful that I did not get any answer in time. My first preference is still Python and Jupyter, but if I have to code and present in R, I prefer R markdown. – Gaurav Singhal Dec 03 '18 at 06:50

2 Answers2

3

I had exactly the same issue. I closed Anaconda, opened it again and then updated the kernel; Finally, it worked again without any error.

conda install -c r r-essentials
Hadij
  • 3,661
  • 5
  • 26
  • 48
  • I have changed my laptop, so for me there is no way to know if that is the right answer. Today I installed miniconda and IRkernel and my code seems to work. So I will accept this answer. – Gaurav Singhal Mar 16 '19 at 10:45
1

Restarting the kernel worked fine with me.

SL3ND3RM4N
  • 11
  • 2
  • 1
    Just add my two cents: Actually worked for me. My guess is that I've used the png() and dev.off() function before and it might have messed with some config – Ochetski Jul 01 '20 at 21:26