7

I have a question related to R Shiny. So I want to have the tooltip which can show the concrete information of a data point when I put my mouse on the point. Anyone has ideas how to do it?

Sample codes are more than welcomed.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2564888
  • 121
  • 1
  • 3
  • 1
    What have you tried? Take a look at rCharts http://ramnathv.github.io/rCharts/. The first example seems to be what you're looking for – Jake Burkhead Jul 21 '13 at 03:19
  • 1
    All js libraries with rCharts support tooltips. You may also want to take a look at [SVGAnnotation](http://www.omegahat.org/SVGAnnotation/) that allows tooltips with grid graphics. – Ramnath Jul 21 '13 at 23:23

2 Answers2

6

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.

Another option

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.

Community
  • 1
  • 1
Ram Narasimhan
  • 22,341
  • 5
  • 49
  • 55
0

You can now go this with the package ggvis as well. See http://ggvis.rstudio.com/

This is the type of code you would use, in 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")

And then in ui.R, to place the plot you use:

ggvisOutput("plot_id")
ecologician
  • 473
  • 3
  • 9