列中的所有值都用于'键'属性应该是唯一的,但有些值是重复的

时间:2015-10-12 18:43:44

标签: r shiny ggvis

我有一个使用闪亮和ggvis库最终工作的R内置的应用程序 - 有点。我遇到的一个问题是add_tooltip函数会产生以下警告:

All values in column used for 'key' property should be unique, but some values are duplicated.

我使用名为id的列作为我的数据框的关键字,并且我已运行na.omit以消除NA值和duplicated函数测试该列中的重复项;它确认每个值都是唯一的。该列中的值是使用sample函数生成的,替换设置为FALSE。我也通过设置df$id <- 1:nrow(df)来生成它,尽管警告仍然存在。

因为这是一个警告,我仍然可以运行应用程序,但是当我点击工具提示时,我会得到一大堆充满NAs的值。下面是构建&#39;的函数的代码。工具提示的内容以及随后调用该函数的ggvis代码。

allviztip <- function(x) { if(is.null(x))return(NULL) 
row <- allviz[allviz$id == x$id, ]
paste0(row$Ticker)}

allviz %>% ggvis(x=~PriceBook,y=~DivYield,key:=~id,size=~MarketCapinMil,shape=~PayoutCat,fill=~PriceSales) %>%
  layer_points() %>% add_tooltip(allviztip,"click") %>% add_axis('x', title='Price/Book Ratio',title_offset=60,properties=axis_props(labels=list(fontSize=12), title=list(fontSize=18))) %>% 
  add_axis("y", title = "Dividend Yield",title_offset=50,properties=axis_props(labels=list(fontSize=12), title=list(fontSize=18))) %>% 
  add_legend(scales="shape", title="Payout Ratio Category") %>% 
  add_legend(scales="fill", title="Price/Sales Ratio", properties = legend_props(legend = list(y = 100))) %>%
  add_legend(scales="size", title="Market Cap",values=c(1,25,50,100,500,1000,5000,50000,100000,300000),properties = legend_props(legend = list(y = 200))) %>% 
  set_options(duration = 0,height="auto",width="auto") %>%
  scale_numeric(property="fill",range=c("lightblue","darkblue")) }) %>%    bind_shiny("visplot","visplot_ui") ` 

关于如何让工具提示正常工作的任何想法?

0 个答案:

没有答案