首页 > 解决方案 > R plot_ly hoverinfo

问题描述

我在一个闪亮的应用程序中使用 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。有人有更好的主意吗?

标签: rshinyplotly

解决方案


推荐阅读