tooltipster: Tooltips htmlwidget

Description Usage Arguments Examples

Description

Add tooltips to HTML content using the tooltipster jQuery library.

Usage

1
tooltipster(selector = ".tooltip", ...)

Arguments

selector

any valid CSS selector. By default, ".tooltip" will be provided.

...

list of options for tooltipster. See toolipster options for a complete reference.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#devtools::install_github("timelyportfolio/tooltipsterR")

library(tooltipsterR)
library(htmltools)

browsable(
  tagList(
    tags$h1(
      "tooltipsterR htmlwidget"
    ),
    tags$p(
      "With tooltipsterR, we can get fancy ",
      tags$span(
        class = "tooltip",
        style = "border-bottom: 1px dashed #999;",
        title = "look at me",
        "tooltips"
      ),
      "in our html content from R."
    ),
    tooltipster()
  )
)

browsable(
  tagList(
    tags$h1(
      "tooltipsterR htmlwidget"
    ),
    tags$p(
      "With tooltipsterR, we can get fancy ",
      tags$span(
        class = "tooltip",
        style = "border-bottom: 1px dashed #999;",
        title = "look at me",
        "tooltips(right)"
      ),
      "in our html content from R."
    ),
    tooltipster(position="right")
  )
)

## Not run: 

# https://sjp.co.nz/projects/gridsvg/demos/tooltips/
library(gridSVG)
library(lattice)

# Add tooltip attributes to a grob on the DL
garnishAllGrobs <- function(elt) {
  if (inherits(elt, "grob")) {
    garnishGrob(
      elt,
      title = elt$name,
      class = "tooltip"#,
      #style = "pointer-events:all;"
    )
  } else {
    elt
  }
}

# third example from demo(lattice)
## Using a custom panel function to superpose a fitted normal density
## on a Kernel Density Estimate
densityplot(
  ~ height | voice.part, data = singer, layout = c(2, 4),
  xlab = "Height (inches)",
  ylab = "Kernel Density\n with Normal Fit",
  main = list("Estimated Density", cex = 1.4, col = "DarkOliveGreen"),
  panel = function(x, ...) {
    panel.densityplot(x, ...)
    panel.mathdensity(dmath = dnorm, args = list(mean=mean(x),sd=sd(x)))
  }
)

grid.DLapply(garnishAllGrobs)

browsable(
  tagList(
    HTML(XML::saveXML(grid.export(name = NULL)$svg)),
    tooltipster()
  )
)


# requires the github version of tmap
#  devtools::install_github("mtennekes/tmap")
library(tmap)
library(dplyr)
data(World)
data(metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100

(tm_shape(World) +
  tm_polygons("income_grp", palette="-Blues", contrast=.7, id="name", title="Income group") +
  tm_shape(metro) +
  tm_bubbles("pop2010", col = "growth", 
             border.col = "black", border.alpha = .5, 
             style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
             palette="-RdYlBu", contrast=1, 
             title.size="Metro population", 
             title.col="Growth rate (%)", id="name") + 
  tm_layout(legend.bg.color = "grey90", legend.bg.alpha=.5, legend.frame=TRUE, asp=0)) %>% 
  itmap() -> itm

browsable(
  tagList(
    itm,
    tooltipster("g")
  )
)

## End(Not run)

timelyportfolio/tooltipsterR documentation built on May 31, 2019, 2:14 p.m.