plotly output not displayed in viewer

Hello all - First time post. Hope to find some help on some issues I've been having after updating to Rstudio 2024.04.1 build 748 earlier this week.

My plotly code was written in a previous version of Rstudio, and used to run perfectly, and the plot would be displayed in the Viewer pane. But now that I updated R, Rstudio and the plotly package, the code runs without returning an error, but the Viewer pane is blank and empty. I can find the plot with Export > Save as a Web page, save it, and it opens fine a browser window, but (obviously) it would feel easier to have it displayed directly in the Viewer pane like I used to. The plot is also generated correctly and embedded when I compile the report. So to my understanding, it should mean that the code in itself is OK.

Inspect element > console returns a handful of errors: "Failed to load resource: the server responded with a status of 404 (not found)" and "Failed to load resource: net: : ERR_SOCKET_NOT_CONNECTED"... So I am guessing the Viewer pane or my R session is not set up correctly somehow when I updated? I uninstalled and re-install R and Rstudio a couple of times now, but no luck unfortunately.

After looking around online, I also "played around" with Global options > R Markdown > Show Output Preview, and specified "Viewer Pane". I also unchecked "show output inline for all Markdown documents". But the Viewer Pane is still blank and empty :frowning:

I hope it is an easy fix. I apologize in advance if this is a stupid question, and if I made a mistake somewhere along the install process. Any help would be greatly appreciated! Many thanks in advance. Steph

For reference, I am using
R version 4.4.0 (2024-04-24 ucrt)
Rstudio 2024.04.1 build 748
plotly 4.10.4
My understanding is that they all are the latest versions.

here is a simple example of a typical chunk of code I am running:

library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")
fig <- df %>%  plot_ly(
    y = ~total_bill,
    type = 'violin',
    box = list(visible = T),
    meanline = list(visible = T ), 
    x0 = 'Total Bill'  ) 
fig <- fig %>%  layout(yaxis = list(title = "",  zeroline = F))
fig
1 Like

You mentioned the R Markdown settings. If you run your code chunk in the RStudio console (or as a .R script file), does it work?

It works fine for me (latest versions of R and RStudio), with the caveat that if I source the script containing your code it creates but does not display fig. If I then ctrl-click the last line or run fig in the console, the plot shows up in the viewer. (This is in my experience normal. When I source a script that ends with an output line, I typically have to rerun that line to get the output, whether text or image.)

1 Like

Thanks for posting this, I am having the same issue and error messages while trying to generate a plotly plot with the RStudio viewer with the same versions of R, RStudio, and plotly, and using windows 11 build 22631.3593, were you able to figure out the issue?

UPDATE: updating to R version 4.4.1 (2024-06-14) fixed the issue for me

1 Like

I have been using RStudio and plotly for ~10 years. It worked fine yesterday and today the same symptoms that are described here a minimal reproducable example is as follows.

library(plotly)
fig <- plot_ly(x = 1:10, y = 1:10, type = 'scatter', mode='markers')
show(fig)

That code produces no visible plot in the viewer though the "Remove current viewer item" becomes active. As stated earlier if I save as result as webpage I can view it in the browser. If I save it as an image it comes out as a white rectangle. I tried uninstalling and re-installing Rstudio just to see if anything would be different. Nothing was. Still does not work.

Could this be related?