cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

R plots not rendering

plankton
New Contributor

Has anyone been experiencing the issue of R plots not rendering in notebooks, starting a few days ago?

t's not related to splarkly or plotly, or specifc data types, or anything. For example in base R: plot(1:3, 5:7) calculates without error, but does not display a graphic. Re-starting cluster, re-attaching cluster to notebook, etc. make no difference.

It's an R thing because running

%python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [5, 6, 7])
display(plt)
does what you'd expect.
9 REPLIES 9

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @plankton,

I tried this in my local workspace, and it seems to work. Can you also share a snapshot? I don't see any reported issues internally either.

Ashwin_DSA_0-1779361645739.png

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***

You have misunderstood and have run a piece of code OP confirmed DOES work. The issue is with R plots not displaying.

 

I am having the same issues with R plots failing to display.

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @LiamM87,

Apologies. I misread the ask. I have now tested an R sample, and that works for me too. 

Here is what I tested.

%r
# Minimal R graphics diagnostics for Databricks notebooks

cat("R version:", R.version.string, "\n")
cat("Capabilities:\n")
print(capabilities())

cat("\nCurrent graphics device before plotting:\n")
print(dev.list())

# 1) Base plot
plot(1:3, 5:7, main = "Base R plot", col = "blue", pch = 19)

cat("\nGraphics device after base plot:\n")
print(dev.list())

# 2) Explicitly force a new page, then another base plot
plot.new()
plot.window(xlim = c(1, 3), ylim = c(5, 7))
points(1:3, 5:7, col = "red", pch = 19)
title("Explicit plot.new / plot.window")

# 3) ggplot2 test, if installed
if (requireNamespace("ggplot2", quietly = TRUE)) {
  p <- ggplot2::ggplot(
    data.frame(x = 1:3, y = 5:7),
    ggplot2::aes(x, y)
  ) +
    ggplot2::geom_point(color = "darkgreen", size = 3) +
    ggplot2::ggtitle("ggplot2 test")
  print(p)
} else {
  cat("\nggplot2 not installed\n")
}

# 4) Device-to-file test: proves R graphics itself is working even if inline render is broken
png("/tmp/r_plot_test.png", width = 800, height = 600)
plot(1:3, 5:7, main = "PNG device test", col = "purple", pch = 19)
dev.off()

cat("\nPNG written to /tmp/r_plot_test.png\n")
%r
png("/dbfs/FileStore/r_plot_test.png", width = 800, height = 600)
plot(1:3, 5:7, main = "PNG device test", col = "purple", pch = 19)
dev.off()

displayHTML('<img src="/files/r_plot_test.png" width="700">')

And the output did render correctly.

Ashwin_DSA_0-1779367956491.png

However, I did see another internal user raise a similar issue. So, this could be a recent regression. I will watch that issue and share any developments. 

Could you confirm what compute you're using: serverless or all-purpose/classic, and which Databricks Runtime version? If this is serverless, that may explain it, since R isn't supported there.

A few quick checks that would also help:

  • Does it happen in more than one browser?
  • Does it reproduce in a brand-new notebook?
  • If you run a simple %r cell with just plot(1:3, 5:7), do you see the same behaviour?
  • If you write the plot to a file and display that file, does it render?

If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.

 

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***

riabenko
New Contributor

I have the same issue, both in Chrome and Safari, in all notebooks including new ones, plot(1:3, 5:7) does not display anything. Device to file example from the message above works.

plankton
New Contributor

The built-in png device does not render. The plot object is generated silently, which is the issue. This is the only direct plot support for base R and ggplot2 plots. I have many ggplots built in critical analyses that all require time-intensive workarounds until this issue is resolved.

Now displayHTML still works like before, but is so much less economical in code. Interactive plots and dashboards are a different use-case, and I also use these daily and understandably have to deploy them through JavaScript and html service.

That said, a work around for the current png device problem which requires retooling our notebooks is to wrap (base R plots / ggplots / dygraphs / plotly/ etc) in shiny apps. Clumsy, but still works. BTW, this has long been the case with plotly outputs - cannot be rendered directly in R notebooks like they can in python notebooks.

And in the very worst case, if we desperately need those plots, the other bandaid is R df → Spark df → temp view → pandas df → matplotlib. Ugh! I know.

But please DataBricks, restore our direct png renders

plankton
New Contributor

forgot these:

  • Issue occurs in old and new notebooks.
  • Runtime: 14.3 LTS (includes Apache Spark 3.5.0, Scala 2.12)

riabenko
New Contributor

The device to file workaround doesn't work for complex plots from ggarrange. 
I also stopped seeing plots in all old notebooks.  

Hope this is fixed soon.

TomB
Visitor

One very inadequate workaround is to use the focus mode (Ctrl + Alt + o) on a cell to see that cell and output, which will show the R plot even if it doesn't show in the notebook per se. It very much does not replace the purpose of having notebooks, but at least you can see your plots one at a time.

plankton
New Contributor

Nice one! This never occured to me. You're right, a small peek is better than complete blindness.