eventdrop: Create an EventDrop timeline

Description Usage Examples

Description

eventdrop provides an interactive d3.js htmlwidget for EventDrop timelines.

Usage

1
2
eventdrop(data = NULL, name = NULL, date = NULL, ..., width = NULL,
  height = NULL, elementId = NULL)

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
# install from github
# devtools::install_github("timelyportfolio/eventdropR")

library(eventdropR)

# make some sample data
df <- data.frame(
  # random times 30 days plus or minus current time
  date = Sys.time() + runif(1000, -30, 30) * 24 * 60 * 60,
  # make up five groups
  group = paste0("grp_", LETTERS[runif(1000,1,5)]),
  stringsAsFactors = FALSE
)

# defaults
# date argument not needed since the date is in column date
eventdrop(
  df,
  name = "group" #if df column named "name" would not need
)

# demonstrate how to set some options
eventdrop(
  df,
  name = "group",
  labelsWidth = 150,
  hasBottomAxis = TRUE,
  mouseover = htmlwidgets::JS('function(d){console.log(d)}')
)

# demonstrate how to use with shiny and get events
#  can easily build this into our htmlwidget
ed <- eventdrop(
  df,
  name = "group",
  mouseover = htmlwidgets::JS(
    '
function(d){
  console.log(d);
  if(typeof(Shiny)!=="undefined") {
    Shiny.onInputChange("eventdrop_click", {data:d});
  }
}
'
  )
)

ed

# now integrate in simple shiny app
library(shiny)
shinyApp(
  ui = ed,
  server = function(input, output, session){
    observeEvent(input$eventdrop_click,{
      str(input$eventdrop_click)
    })
  }
)

timelyportfolio/eventdropR documentation built on May 31, 2019, 1:49 p.m.