我有一个与R Shiny 相关的问题。所以我想要一个工具提示,当我把鼠标放在点上时,它可以显示数据点的具体信息。任何人都有想法怎么做?
示例代码非常受欢迎。
I have seen this done in rCharts
by Ramnath V, in his NYTimes graphics example. rCharts sits on top of Shiny.
You can check out a fully reproducible and clearly described example here.
This piece of code is what you are after:
require(rCharts)
p1 <- rPlot(SOG ~ yearID, data = team_data, type = 'point',
size = list(const = 2), color = list(const = '#888'),
tooltip="function(item){return item.SOG +'\n' + item.name + '\n' + item.yearID}"
)
p1$print('chart1')
Notice how he uses a Javascript function as an argument to tooltip for rPlot.
You can also try wrapping your element inside a tags$div()
Though not exactly what you are looking for, in this related question, Joe Cheng suggests exactly that, but for UI.R. (The difference is that in that example the tool-tip is a static text.)
Say you have a sliderInput
:
tags$div(title="this static text will show up in the tooltip",
sliderInput( # parameters here
)
)
Hope that helps you move forward.
您现在也可以使用该软件包ggvis
。见http://ggvis.rstudio.com/
这是您将使用的代码类型,在server.R
:
library(ggvis)
df %>% ggvis(~x, ~y) %>% layer_points() %>%
add_tooltip(function(x) paste0(names(x), ": ",
format(x), collapse = "<br />"), "hover") %>%
bind_shiny("plot_id")
然后在 ui.R 中,放置您使用的绘图:
ggvisOutput("plot_id")