Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in file(con, "rb") : cannot open the connection when generating a plot in a presentation with plotly

Tags:

r

I am using R 3.3.3 and I am working on an R presentation trying to plot a ggplot graph with plotly. My chunk code in the R markdown file is:

```{r plot, echo=FALSE, message=TRUE, warning=TRUE}

G <- ggplot(data=gender_gap, aes(x=value_girls, y=value_boys, color=gender_gap))+ geom_point()+ geom_text(label=gender_gap$LOCATION, hjust=1, vjust=1, size=4)+ geom_abline(intercept = 0, slope = 1)

ggplotly(G)
```

The plot is nicely printed in the viewer, but in the slide I get the following message:

"Error in file(con, "rb") : cannot open the connection"

In advance thank you for your wise advice!

like image 770
Maria Avatar asked Dec 16 '16 15:12

Maria


2 Answers

I too was having the same problem but the below code solved mine.

```{r}
library(plotly)
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p=plot_ly(d, x = ~carat, y = ~price, color = ~carat,
    size = ~carat, text = ~paste("Clarity: ", clarity))
htmlwidgets::saveWidget(as.widget(p), file = "demo.html")
```
<iframe src="demo.html" style="position:absolute;height:100%;width:100%"></iframe>
like image 106
Jesin Fahad Avatar answered Nov 15 '22 13:11

Jesin Fahad


I had the same issue and fixed it by creating the presentation with R Markdown instead of R presentation.

enter image description here

I chose Html ioslides as Output format and it went smoothly.

enter image description here

like image 1
Julien Massardier Avatar answered Nov 15 '22 14:11

Julien Massardier