This is a test version of Biostars. For the public version, visit https://www.biostars.org.
saving ggplotly as html

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

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)

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

1 answer

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

thank you very much Antonio, simply as that!

Log in to answer this question.