R Tooltip data point

I have a question related to R Shiny. So I want to have a tooltip that can display specific information about a data point when I click on it with a mouse. Anyone have any ideas how to do this?

Code examples are more than welcome.

+7
r shiny tooltip rcharts
source share
2 answers

I saw this done in rCharts Ramnath V, in his graphic example of NYTimes. rCharts sits on top of Brilliant. You can check out the fully reproducible and clearly described example here .

This piece of code is what you need:

 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 it uses the Javascript function as an argument to the tooltip for rPlot.

Another option

You can also try wrapping your element inside tags$div()

Although not quite what you are looking for in this related question , Joe Cheng offers exactly that, but for UI.R. (The difference is that in this example, the tooltip is static text.)

Say you have sliderInput :

 tags$div(title="this static text will show up in the tooltip", sliderInput( # parameters here ) ) 

Hope this helps you move forward.

+6
source share

Now you can go with the ggvis package. 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 post the plot you are using:

 ggvisOutput("plot_id") 
0
source share

All Articles