Skip to content

Instantly share code, notes, and snippets.

@pvictor
Last active August 21, 2018 14:41
Show Gist options
  • Save pvictor/49fdb05d362acca8d6b94d69345a5046 to your computer and use it in GitHub Desktop.
Save pvictor/49fdb05d362acca8d6b94d69345a5046 to your computer and use it in GitHub Desktop.
Linked tooltip between charts in {billboarder} https://github.com/dreamRs/billboarder
# on CRAN now (version 0.2.3)
library(billboarder)
# data
data("economics", package = "ggplot2")
# helper fun
make_line <- function(var, title, percent = TRUE) {
billboarder() %>%
bb_linechart(data = economics[, c("date", var)]) %>%
bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>%
bb_y_axis(tick = list(format = if (percent) suffix("%"))) %>%
bb_legend(show = FALSE) %>%
bb_x_grid(show = TRUE) %>%
bb_y_grid(show = TRUE) %>%
bb_labs(title = title) %>%
bb_tooltip(linked = list(name = "my-tooltip")) # <--- Id for linking tooltip
}
# make_line("psavert", "Personal savings rate", TRUE)
# make_line("uempmed", "Number of unemployed", TRUE)
# make_line("pce", "Personal consumption expenditures", FALSE)
# make_line("pop", "Total population", FALSE)
# app
library(shiny)
ui <- fluidPage(
fluidRow(
column(
width = 10, offset = 1,
tags$h2("Linked tooltip in {billboarder}"),
fluidRow(
column(width = 6, billboarderOutput("g1")),
column(width = 6, billboarderOutput("g2")),
column(width = 6, billboarderOutput("g3")),
column(width = 6, billboarderOutput("g4"))
)
)
)
)
server <- function(input, output, session) {
output$g1 <- renderBillboarder(make_line("psavert", "Personal savings rate", TRUE))
output$g2 <- renderBillboarder(make_line("uempmed", "Number of unemployed", TRUE))
output$g3 <- renderBillboarder(make_line("pce", "Personal consumption expenditures", FALSE))
output$g4 <- renderBillboarder(make_line("pop", "Total population", FALSE))
}
shinyApp(ui, server)
@pvictor
Copy link
Author

pvictor commented Aug 3, 2018

linked-tooltip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment