R plot_ly hoverinfo

时间:2018-04-30 14:56:18

标签: r shiny plotly

我在一个闪亮的应用程序中使用plot_ly。我有以下功能

plot_ly(df, x = ~x, y = ~y , key = df$id, type='scatter', mode="markers",
name = "Clusters", opacity = point.opacity, text = df$id, hoverinfo = "text")

如果 df $ id 的长度不为0,那么一切都很好。如果长度为0,因为没有数据可用,我会收到以下错误:Error in : Column 'hoverinfo' must be length 0, not 1。如果我省略了hoverinfo,那么空数据集的一切都很好。

我该如何解决这个问题?我试图使用ifelse,但这不起作用。我的解决方案是定义一个if语句,然后使用或不使用hoverinfo调用plot_ly。有没有人有更好的主意?

0 个答案:

没有答案
相关问题