我一直在寻找答案,但没有一个能解决我遇到的问题。我正在创建一个带有许多图形的R Shiny应用程序。一个是交互式散点图,用户可以将鼠标悬停在点上并弹出信息。散点图出现了,但我无法获取弹出的ggvis工具提示信息,并且我没有错误。它似乎忽略了add_tooltip的html部分。
UI:
shinyUI(fluidPage( theme = "bootstrap.css",
tabPanel("Interactive ScatterPlot",
#uiOutput("ggvis_ui"), #have tried with and without this
ggvisOutput("scatter_plot")
)
)
)
服务器:
shinyServer(function(input, output, session) {
tooltipValues <- function(x) {
print(1) #doesn't print
if(is.null(x)) return(NULL)
print(x) #doesn't print
row <- out[out$id==x$id,]
paste0("Row: ", row$rowNames, "<br>Column: ", row$colNames)
}
scatter <- reactive({
indices1 <- tempJaccard() #this works
out <- scatterPlotDF(indices1) #scatterPlotDF is working, out is a dataframe
out %>%
ggvis(x=~rowP, y=~colP, fill=~rowNames) %>%
layer_points(size := 50, size.hover:=200, key:=~id) %>% #the points do magnify on hover
add_axis("x",title="Budget Description Percentile") %>%
add_axis("y",title="OV-5a Percentile") %>%
add_tooltip(tooltipValues,"hover")
})
scatter %>% bind_shiny("scatter_plot") #I've tried different versions of this line
#end server
)}
当我在命令控制台中运行它而不是在我的完整应用程序中(在R Studio和Chrome中)时,我的散点图和工具提示都有效。我已经查看了stackoverflow问题24519980和24959609以及:
http://rpackages.ianhowson.com/cran/ggvis/man/add_tooltip.html
我想要这样的事情:
http://shiny.rstudio.com/gallery/movie-explorer.html
源代码在github上。