# Error with plot\_ly() in R : Error in vapply(nms, function(x)

**URL:** <https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953>\
**Category:** Plotly R\
**Created:** [April 29, 2016, 5:38pm UTC](https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953 "2016-04-29T17:38:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kilian](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kilian](https://community.plotly.com/u/kilian)\
**Post date:** [April 29, 2016, 5:38pm UTC](https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953/1 "2016-04-29T17:38:19Z")

</div>

Hello,  
When doing this:

> p=ggplot(data,aes(x,fill=(y)))  
> p=p+geom\_bar()  
> p  
> plot\_ly(p)

I had this error message :  
Error in vapply(nms, function(x) { : values must be length 1,  
but FUN(X[[1]]) result is length 0

Could you please tell me how to resolve the problem?  
Thank you

---

<div class="post-metadata">

**Author:** ![royr2](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@royr2](https://community.plotly.com/u/royr2)\
**Post date:** [May 2, 2016, 8:55am UTC](https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953/2 "2016-05-02T08:55:40Z")

</div>

Could you post at least a subset of your data? It’ll help troubleshoot.

---

<div class="post-metadata">

**Author:** ![timelyportfolio](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@timelyportfolio](https://community.plotly.com/u/timelyportfolio)\
**Post date:** [May 4, 2016, 1:41pm UTC](https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953/3 "2016-05-04T13:41:02Z")

</div>

Without a fully reproducible example, it is hard to know if this will solve your problem or not, but in general if you are converting a `ggplot2` plot, you should use `ggplotly` instead of `plot_ly`. `plot_ly` is designed for directly building a Plotly `htmlwidget` without help from `ggplot2`. So, code something like the following should work.

```auto
p=ggplot(data,aes(x,fill=(y)))
p=p+geom_bar()
p
ggplotly(p)

```

---

<div class="post-metadata">

**Author:** ![kilian](https://avatars.discourse-cdn.com/v4/letter/k/ee7513/32.png) [@kilian](https://community.plotly.com/u/kilian)\
**Post date:** [June 2, 2016, 9:47am UTC](https://community.plotly.com/t/error-with-plot-ly-in-r-error-in-vapply-nms-function-x/953/4 "2016-06-02T09:47:14Z")

</div>

Thank you verymuch, it works with ggplotly indeed !
