Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.Rhistory
.RData
.DS_Store
.directory
rsconnect
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ Imports:
htmlwidgets (>= 0.6),
htmltools (>= 0.3.5),
zoo (>= 1.7-10),
xts (>= 0.9-7)
xts (>= 0.9-7),
shiny (>= 0.10.2.1)
Suggests:
testthat
Enhances: rmarkdown (>= 0.3.3), shiny (>= 0.10.2.1)
Enhances: rmarkdown (>= 0.3.3)
RoxygenNote: 5.0.1
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(dyAnnotation)
export(dyAxis)
export(dyCSS)
export(dyCallbacks)
export(dyCrosshair)
export(dyEvent)
export(dyHighlight)
export(dyLegend)
Expand All @@ -18,12 +19,17 @@ export(dyRoller)
export(dySeries)
export(dySeriesData)
export(dyShading)
export(dySliderInput)
export(dyUnzoom)
export(dygraph)
export(dygraphOutput)
export(renderDygraph)
importFrom(grDevices,col2rgb)
importFrom(htmltools,htmlDependency)
importFrom(htmlwidgets,JS)
importFrom(magrittr,"%>%")
importFrom(shiny,animationOptions)
importFrom(shiny,icon)
importFrom(stats,end)
importFrom(stats,start)
importFrom(zoo,as.yearmon)
Expand Down
103 changes: 103 additions & 0 deletions R/plugin.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,106 @@ dyPlugin <- function(dygraph, name, path, options = list(), version = "1.0") {
# return dygraph
dygraph
}

#' dyUnzoom
#'
#' @inheritParams dyPlugin
#'
#' @return A dygraph with the specified plugin enabled.
#'
#' @details The dyUnzoom plugin adds an "Unzoom" button to the graph when it's displaying
#' in a zoomed state (this is a bit more discoverable than the default double-
#' click gesture for unzooming). Note that this plugin has no options (see
#' below for an example with options).
#'
#' @examples
#' library(dygraphs)
#' dygraph(mdeaths) %>%
#' dyUnzoom()
#'
#' @export
dyUnzoom <-function(dygraph) {
dyPlugin(
dygraph = dygraph,
name = "Unzoom",
path = system.file("examples/plugins/unzoom.js", package = "dygraphs")
)
}

#' dyCrosshair
#'
#' @inheritParams dyPlugin
#' @param direction Direction for crosshairs. Defaults to 'both'. Valid arguments are
# 'both', 'horizontal', and 'vertical'.
#'
#' @return A dygraph with the specified plugin enabled.
#'
#' @details The dyCrosshair plugin draws a crosshair line over the point closest to the
#' mouse when the user hovers over the graph. It has a "direction" option which
#' is provided in the R wrapper function and then forwarded to the plugin using
#' the "options" argument to dyPlugin.
#'
#' @examples
#' library(dygraphs)
#' dygraph(mdeaths) %>%
#' dyCrosshair()
#'
#' @export
dyCrosshair <- function(dygraph, direction = c("both", "horizontal", "vertical")) {
dyPlugin(
dygraph = dygraph,
name = "Crosshair",
path = system.file("examples/plugins/crosshair.js", package = "dygraphs"),
options = list(direction = match.arg(direction))
)
}

#' dySliderInput
#'
#' @inheritParams dyPlugin
#' @param color Color to draw slider. Defaults to 'red'.
#' @param strokePattern Line type for slider. Defaults to 'dashed'. Valid arguments are
#' 'dashed', 'solid', 'dotted', and 'dotdash'.
#' @param animate 'TRUE' to show simple animation controls with default settings;
#' 'FALSE' not to; or a custom settings list, such as those created using 'animationOptions'.
#'
#' @return A dygraph with the specified plugin enabled.
#'
#' @details The dySliderInput plugin turns the dyDygraph into a slider input widget. The
#' user can click on a point along the graph and the graph will place a vertical
#' line on the graph. The user can also use the animation options to scroll
#' through points along the graph.
#'
#' @examples
#' library(dygraphs)
#' dygraph(mdeaths) %>%
#' dySliderInput()
#'
#' @importFrom grDevices col2rgb
#' @importFrom shiny icon
#' @importFrom shiny animationOptions
#'
#' @export
dySliderInput <- function(dygraph, color = 'red', strokePattern = c('dashed', 'solid', 'dotted', 'dotdash'), animate = FALSE) {
# process args
stopifnot(length(color)==1)
col <- paste(col2rgb(color)[,1], collapse=',')
alpha <- (col2rgb(color, alpha=TRUE)[4,1] / 255)
if (identical(animate, TRUE))
animate <- animationOptions()
if (identical(animate, FALSE))
animate <- NULL
if (!is.null(animate)) {
if (is.null(animate$playButton))
animate$playButton <- as.character(icon("play", lib = "glyphicon"))
if (is.null(animate$pauseButton))
animate$pauseButton <- as.character(icon("pause", lib = "glyphicon"))
}
# add plugin
dyPlugin(
dygraph = dygraph,
name = "SliderInput",
path = system.file("examples/plugins/sliderinput.js", package = "dygraphs"),
options = list(strokeStyle = paste0(col, ',', alpha), strokePattern=resolveStrokePattern(match.arg(strokePattern)), animate = animate)
)
}
1 change: 1 addition & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dygraphs 1.1.1.3 (unreleased)

* Support for non-date values in shiny input bindings (#132)

* Fix for inconsistant format in date-time callbacks

dygraphs 1.1.1.2
--------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions inst/examples/plugins/plugins.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ dyCrosshair <- function(dygraph, direction = c("both", "horizontal", "vertical")
)
}


# Our plugin wrapper functions can now be incorporated directly into a dygraph
# pipeline along with other dygraphs functions:

library(dygraphs)
dygraph(ldeaths) %>%
dyRangeSelector() %>%
dyUnzoom() %>%
dyCrosshair(direction = "vertical")
dyCrosshair(direction = "vertical") %>%



Loading