saving ggplotly as html
1
0
Entering edit mode
3.7 years ago
gubrins ▴ 290

Heys, I'm trying to save as a html file an output from ggplotly in R and I'm getting all the time this error:

Error in FUN(X[[i]], ...) :subscript out of bounds

The code of my plot is quite simple:

b <- ggplot(pca, aes(PC1, PC2, label=ind, col=col,labels=ID))+ geom_point(size = 2)

And the problem appears when I try to save it as an html file:

htmlwidgets::saveWidget(as_widget(b), "index.html")

Any idea of how can I fix that? Thanks in advance!

R ggplotly • 12k views
ADD COMMENT
1
Entering edit mode

If you are using Rstudio, Viewer window allows you to export the graphical output from plotly/ggplotly as html (Viewer > export > save as web page).

Try this:

library(ggplot2)
library(plotly)
ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species)
ggplotly(ggiris)
ADD REPLY
0
Entering edit mode

Thanks for your answer, at the end I solved it in a similar way, creating an Rmarkdown html file

ADD REPLY
4
Entering edit mode
3.7 years ago

Hi,

The problem is that you are not giving a plotly object, but instead a ggplot object. Do the following:

l <- plotly::ggplotly(b)

htmlwidgets::saveWidget(l, "index.html")

I hope this answers your question,

António

ADD COMMENT
0
Entering edit mode

thank you very much Antonio, simply as that!

ADD REPLY

Login before adding your answer.

Traffic: 1809 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6