Question: saving ggplotly as html
0
gravatar for gabri.mochales
7 weeks ago by
gabri.mochales30 wrote:

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!

ggplotly R • 208 views
ADD COMMENTlink modified 7 weeks ago by antonioggsousa1.5k • written 7 weeks ago by gabri.mochales30
1

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 REPLYlink modified 7 weeks ago • written 7 weeks ago by cpad011214k

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

ADD REPLYlink written 7 weeks ago by gabri.mochales30
4
gravatar for antonioggsousa
7 weeks ago by
antonioggsousa1.5k
antonioggsousa1.5k wrote:

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 COMMENTlink written 7 weeks ago by antonioggsousa1.5k

thank you very much Antonio, simply as that!

ADD REPLYlink written 7 weeks ago by gabri.mochales30
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2042 users visited in the last hour