From cec4bd30d3866028d1a88f033e38e89107793104 Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Mon, 10 Dec 2018 14:39:52 -0500 Subject: [PATCH 1/9] fixed z-index; added color option - the cross-hair canvas was below the main canvas, such that if shading was applied, would be below the shading and not visible. - added optional color setting for crosshairs --- inst/plugins/crosshair.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/inst/plugins/crosshair.js b/inst/plugins/crosshair.js index 0df61d4..bca7c18 100644 --- a/inst/plugins/crosshair.js +++ b/inst/plugins/crosshair.js @@ -17,8 +17,13 @@ Dygraph.Plugins.Crosshair = (function() { var crosshair = function(opt_options) { this.canvas_ = document.createElement("canvas"); + this.canvas_.style.zIndex = 1; + this.canvas_.style.position = "absolute"; + this.canvas_.style.pointerEvents = "none"; + opt_options = opt_options || {}; this.direction_ = opt_options.direction || null; + this.color_ = opt_options.color || "rgba(0, 0, 0,0.3)" }; crosshair.prototype.toString = function() { @@ -52,7 +57,7 @@ Dygraph.Plugins.Crosshair = (function() { var ctx = this.canvas_.getContext("2d"); ctx.clearRect(0, 0, width, height); - ctx.strokeStyle = "rgba(0, 0, 0,0.3)"; + ctx.strokeStyle = this.color_; ctx.beginPath(); var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering From a409f827dd9f6eb0f5d14d45f1ae3ed691b1d91e Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Mon, 10 Dec 2018 15:04:27 -0500 Subject: [PATCH 2/9] added color option to dyCrosshair() --- R/plugins.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/plugins.R b/R/plugins.R index 349b1a6..9fb7880 100644 --- a/R/plugins.R +++ b/R/plugins.R @@ -29,6 +29,7 @@ dyUnzoom <-function(dygraph) { #' @param dygraph Dygraph to add plugin to #' @param direction Crosshair direction. Valid options are: "both", "horizontal", #' "vertical" +#' @param color Crosshair color in RGB form ("#ff0088" or rgb(255,0,136)), default black and 0.3 alpha. #' #' @return Dygraph with Crosshair plugin enabled #' @@ -39,12 +40,12 @@ dyUnzoom <-function(dygraph) { #' dyCrosshair(direction = "vertical") #' #' @export -dyCrosshair <- function(dygraph, direction = c("both", "horizontal", "vertical")) { +dyCrosshair <- function(dygraph, direction = c("both", "horizontal", "vertical"), color=rgb(0,0,0,0.3)) { dyPlugin( dygraph = dygraph, name = "Crosshair", path = system.file("plugins/crosshair.js", package = "dygraphs"), - options = list(direction = match.arg(direction)) + options = list(direction = match.arg(direction), color=color) ) } From 1dd90a96ef56e7ba33405632385e7af89fed8fca Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Mon, 10 Dec 2018 15:08:07 -0500 Subject: [PATCH 3/9] updated R documentation --- man/dyCrosshair.Rd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/man/dyCrosshair.Rd b/man/dyCrosshair.Rd index 8846fd8..48e5f59 100644 --- a/man/dyCrosshair.Rd +++ b/man/dyCrosshair.Rd @@ -7,13 +7,15 @@ 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.} \usage{ -dyCrosshair(dygraph, direction = c("both", "horizontal", "vertical")) +dyCrosshair(dygraph, direction = c("both", "horizontal", "vertical"), color=rgb(0,0,0,0.3)) } \arguments{ \item{dygraph}{Dygraph to add plugin to} \item{direction}{Crosshair direction. Valid options are: "both", "horizontal", "vertical"} + +\item{color}{Color and alpha (transparency) of crosshair} } \value{ Dygraph with Crosshair plugin enabled @@ -28,6 +30,6 @@ the "options" argument to dyPlugin. library(dygraphs) dygraph(ldeaths) \%>\% dyRangeSelector() \%>\% - dyCrosshair(direction = "vertical") - + dyCrosshair(direction = "vertical", + color=rgb(1.0,0,0,0.5)) } From 371a57948e77ced15b83d17914cf61f02d44dcb5 Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Mon, 10 Dec 2018 15:08:27 -0500 Subject: [PATCH 4/9] Update dyCrosshair.Rd --- man/dyCrosshair.Rd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/man/dyCrosshair.Rd b/man/dyCrosshair.Rd index 48e5f59..a3a4539 100644 --- a/man/dyCrosshair.Rd +++ b/man/dyCrosshair.Rd @@ -30,6 +30,5 @@ the "options" argument to dyPlugin. library(dygraphs) dygraph(ldeaths) \%>\% dyRangeSelector() \%>\% - dyCrosshair(direction = "vertical", - color=rgb(1.0,0,0,0.5)) + dyCrosshair(direction = "vertical", color=rgb(1.0,0,0,0.5)) } From 24946d274672a4cf30b4d7a8d0bdd90bc50fac7f Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Mon, 10 Dec 2018 19:12:25 -0500 Subject: [PATCH 5/9] updated documentation for dyCrosshair --- docs/gallery-plugins.Rmd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/gallery-plugins.Rmd b/docs/gallery-plugins.Rmd index dc22132..d0a4f1c 100644 --- a/docs/gallery-plugins.Rmd +++ b/docs/gallery-plugins.Rmd @@ -39,17 +39,18 @@ Try zooming the dygraph and note that a "Reset Zoom" button now appears when the #### Plugin Options -The dyCrosshair plugin draws a crosshair line over the point closest to the mouse when the user hovers over the graph (see the JavaScript source code for the plugin here: ). The plugin includes a "direction" option that is provided as an argument to the R wrapper function and then forwarded to the plugin using the "options" argument to `dyPlugin`. +The dyCrosshair plugin draws a crosshair line over the point closest to the mouse when the user hovers over the graph (see the JavaScript source code for the plugin here: ). The plugin includes a "direction" and "color" option that is provided as an argument to the R wrapper function and then forwarded to the plugin using the "options" argument to `dyPlugin`. ```{r} dyCrosshair <- function(dygraph, - direction = c("both", "horizontal", "vertical")) { + direction = c("both", "horizontal", "vertical"), + color = rgb(0,0,0,0.3) { dyPlugin( dygraph = dygraph, name = "Crosshair", path = system.file("plugins/crosshair.js", package = "dygraphs"), - options = list(direction = match.arg(direction)) + options = list(direction = match.arg(direction), color=color) ) } ``` @@ -60,7 +61,7 @@ The plugin can now be used just like any other dygraphs function and can even be dygraph(ldeaths) %>% dyRangeSelector() %>% dyUnzoom() %>% - dyCrosshair(direction = "vertical") + dyCrosshair(direction = "vertical", color='#ff00004d') ``` If you hover over the graph you'll see a vertical crosshair drawn at the current position of the mouse. From c7bde7d20cd7c877817e4304f1bddc1a5efaabb8 Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Tue, 11 Dec 2018 09:04:13 -0500 Subject: [PATCH 6/9] adjusted docs --- docs/gallery-plugins.Rmd | 2 +- docs/gallery-plugins.html | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/gallery-plugins.Rmd b/docs/gallery-plugins.Rmd index d0a4f1c..dbb5ccd 100644 --- a/docs/gallery-plugins.Rmd +++ b/docs/gallery-plugins.Rmd @@ -61,7 +61,7 @@ The plugin can now be used just like any other dygraphs function and can even be dygraph(ldeaths) %>% dyRangeSelector() %>% dyUnzoom() %>% - dyCrosshair(direction = "vertical", color='#ff00004d') + dyCrosshair(direction = "vertical", color="#ff00004d") ``` If you hover over the graph you'll see a vertical crosshair drawn at the current position of the mouse. diff --git a/docs/gallery-plugins.html b/docs/gallery-plugins.html index ee2f4e5..0fea1d6 100644 --- a/docs/gallery-plugins.html +++ b/docs/gallery-plugins.html @@ -198,22 +198,23 @@

Simple Example

Plugin Options

-

The dyCrosshair plugin draws a crosshair line over the point closest to the mouse when the user hovers over the graph (see the JavaScript source code for the plugin here: https://github.com/rstudio/dygraphs/blob/master/inst/plugins/crosshair.js). The plugin includes a “direction” option that is provided as an argument to the R wrapper function and then forwarded to the plugin using the “options” argument to dyPlugin.

+

The dyCrosshair plugin draws a crosshair line over the point closest to the mouse when the user hovers over the graph (see the JavaScript source code for the plugin here: https://github.com/rstudio/dygraphs/blob/master/inst/plugins/crosshair.js). The plugin includes a “direction” and "color" option that is provided as an argument to the R wrapper function and then forwarded to the plugin using the “options” argument to dyPlugin.

dyCrosshair <- function(dygraph, 
-                        direction = c("both", "horizontal", "vertical")) {
+                        direction = c("both", "horizontal", "vertical"),
+                        color = rgb(0,0,0,0.3)) {
   dyPlugin(
     dygraph = dygraph,
     name = "Crosshair",
     path = system.file("plugins/crosshair.js", 
                        package = "dygraphs"),
-    options = list(direction = match.arg(direction))
+    options = list(direction = match.arg(direction), color=color)
   )
 }

The plugin can now be used just like any other dygraphs function and can even be composed with other plugins:

dygraph(ldeaths) %>% 
   dyRangeSelector() %>% 
   dyUnzoom() %>% 
-  dyCrosshair(direction = "vertical")
+ dyCrosshair(direction = "vertical", color="#ff00004d")

If you hover over the graph you’ll see a vertical crosshair drawn at the current position of the mouse.

From 5ecc28858216beffe0a33d6862056cb20bfb0dcc Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Tue, 11 Dec 2018 09:07:29 -0500 Subject: [PATCH 7/9] updated DESCRIPTION to include contributer --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 1203cee..34cbf86 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,6 +13,7 @@ Authors@R: c( person("Daniel", "Gromer", role = c("aut", "cph")), person("Benoit", "Thieurmel", role = c("aut", "cph")), person("Kent", "Laukhuf", role = "ctb"), + person("Jonathan", "Shore", role = "ctb"), person(family = "jQuery Foundation", role = "cph", comment = "jQuery library"), person(family = "jQuery contributors", role = c("ctb", "cph"), From cad70516fe459c118c3eb938acaa4f32e2a21e0b Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Wed, 12 Dec 2018 08:54:34 -0500 Subject: [PATCH 8/9] added dyUpdate, allowing in-situ updates of dygraph data --- NAMESPACE | 1 + R/update.R | 63 ++++++++++++++++++++++++++++++++++++ inst/htmlwidgets/dygraphs.js | 24 ++++++++++++++ man/dyUpdate.Rd | 28 ++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 R/update.R create mode 100644 man/dyUpdate.Rd diff --git a/NAMESPACE b/NAMESPACE index b966699..6e38d6e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,6 +40,7 @@ export(dyStackedLineGroup) export(dyStackedRibbonGroup) export(dyStemSeries) export(dyUnzoom) +export(dyUpdate) export(dygraph) export(dygraphOutput) export(renderDygraph) diff --git a/R/update.R b/R/update.R new file mode 100644 index 0000000..bab6ac8 --- /dev/null +++ b/R/update.R @@ -0,0 +1,63 @@ +#' dyUpdate allows in-situ replacement of the rendered timeseries in dygraph within shiny, rather than +#' rerendering the widget on each data change. This can be used for "real-time" update changes in +#' sampling, etc. +#' +#' @param session shiny session +#' @param id graph identifier (refers to the dygraph elementId parameter) +#' @param data the latest data set to be rendered (must have the same number of columns as the original data set) +#' +#' @note +#' See the \href{https://rstudio.github.io/dygraphs/}{online documentation} for +#' additional details and examples. +#' +#' @examples +#' require(shiny) +#' require(dygraphs) +#' +#' app = function () { +#' newdata <- function(n = 1000) { +#' vclose <- cumsum(rnorm(n,sd=0.25)) +#' vlow <- vclose - abs(rnorm(n,sd=0.25)) +#' vhigh <- vclose + abs(rnorm(n,sd=0.25)) +#' vopen <- c(vlow[1], vclose[1:(NROW(vclose)-1)]) +#' times <- as.POSIXct((1:n)*5, origin='2018-1-1 00:00:00', tz='UTC') +#' data.frame(open=vopen, high=vhigh, low=vlow, close=vclose, row.names = times) +#' } +#' graph = function() { +#' bars <- newdata() +#' v1 <- dygraph(bars, height=650, width='100%', elementId='graph1') %>% +#' dyCandlestick() %>% +#' dyOptions(labelsUTC = TRUE) +#' htmltools::browsable(v1) +#' } +#' +#' ui <- fluidPage( +#' sidebarLayout(sidebarPanel(actionButton("button", "regenerate")), +#' mainPanel(graph()))) +#' +#' events <- function (input, output, session) { +#' observeEvent(input$button, { +#' bars <- newdata() +#' dyUpdate (session, 'graph1', bars) +#' }) +#' } +#' +#' shinyApp(ui = ui, server = events, options=list(port=5432, host="127.0.0.1")) +#' } +#' +#' app() +#' +#' @export +dyUpdate <- function(session, id, data) { + if (!xts::is.xts(data)) + data <- xts::as.xts(data) + + times <- as.POSIXct(time(data), origin='2010-1-1 00:00:00', tz='UTC') + data <- zoo::coredata(data) + + # create matrix of time and data columns (time in epoch time seconds) + mat <- cbind(as.numeric(times), data) + + # send data and target graph ID to browser + session$sendCustomMessage(type='dygraph:newdata', list(id=id, data=mat)) +} diff --git a/inst/htmlwidgets/dygraphs.js b/inst/htmlwidgets/dygraphs.js index 3cd0391..a728336 100644 --- a/inst/htmlwidgets/dygraphs.js +++ b/inst/htmlwidgets/dygraphs.js @@ -20,6 +20,30 @@ if (!Array.prototype.indexOf) { }; } +// Add Shiny hook for data update if shiny running +if (HTMLWidgets.shinyMode) { + Shiny.addCustomMessageHandler("dygraph:newdata", function(msg) { + var id = msg.id; + var data = msg.data; + var container = document.getElementById(id); + var widget = container.htmlwidget_data_init_result.dygraph; + + var existingdata = widget.file_; + var isDate = existingdata.length > 0 && (existingdata[0][0] instanceof Date); + + if (isDate) { + // convert epoch time in seconds (from R) into javascript Date for each row + for (var i = 0; i < data.length ; i++) { + var seconds = data[i][0] + var date = new Date(seconds * 1000); + data[i][0] = date; + } + } + + widget.updateOptions( { 'file': data } ); + }); +} + HTMLWidgets.widget({ name: "dygraphs", diff --git a/man/dyUpdate.Rd b/man/dyUpdate.Rd new file mode 100644 index 0000000..ce6643e --- /dev/null +++ b/man/dyUpdate.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plugins.R +\name{dyUnzoom} +\alias{dyUnzoom} +\title{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).} +\usage{ +dyUnzoom(dygraph) +} +\arguments{ +\item{dygraph}{Dygraph to add plugin to} +} +\value{ +Dygraph with Unzoom plugin enabled +} +\description{ +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). +} +\examples{ +library(dygraphs) +dygraph(ldeaths) \%>\% + dyRangeSelector() \%>\% + dyUnzoom() + +} From 42ca0e341df49777212912d1b8b7ce74ee8b114f Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Wed, 12 Dec 2018 08:59:19 -0500 Subject: [PATCH 9/9] updated documentation --- DESCRIPTION | 2 +- man/dyAnnotation.Rd | 5 +-- man/dyAxis.Rd | 15 +++++---- man/dyCrosshair.Rd | 10 +++--- man/dyGroup.Rd | 8 ++--- man/dyOptions.Rd | 26 ++++++++------- man/dyRangeSelector.Rd | 4 +-- man/dyRibbon.Rd | 4 +-- man/dySeries.Rd | 8 ++--- man/dyUpdate.Rd | 72 +++++++++++++++++++++++++++++++----------- man/dygraph.Rd | 5 +-- 11 files changed, 101 insertions(+), 58 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 34cbf86..f865ca1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,4 +38,4 @@ Imports: Suggests: testthat Enhances: rmarkdown (>= 0.3.3), shiny (>= 0.10.2.1) -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.0 diff --git a/man/dyAnnotation.Rd b/man/dyAnnotation.Rd index 9d52425..58c51fd 100644 --- a/man/dyAnnotation.Rd +++ b/man/dyAnnotation.Rd @@ -6,8 +6,9 @@ \usage{ dyAnnotation(dygraph, x, text, tooltip = NULL, width = NULL, height = NULL, cssClass = NULL, tickHeight = NULL, - attachAtBottom = FALSE, clickHandler = NULL, mouseOverHandler = NULL, - mouseOutHandler = NULL, dblClickHandler = NULL, series = NULL) + attachAtBottom = FALSE, clickHandler = NULL, + mouseOverHandler = NULL, mouseOutHandler = NULL, + dblClickHandler = NULL, series = NULL) } \arguments{ \item{dygraph}{Dygraph to add an annotation to} diff --git a/man/dyAxis.Rd b/man/dyAxis.Rd index 8b5da8c..fd14580 100644 --- a/man/dyAxis.Rd +++ b/man/dyAxis.Rd @@ -4,13 +4,14 @@ \alias{dyAxis} \title{dygraph axis} \usage{ -dyAxis(dygraph, name, label = NULL, valueRange = NULL, logscale = NULL, - ticker = NULL, rangePad = NULL, labelWidth = NULL, labelHeight = NULL, - axisHeight = NULL, axisLineColor = NULL, axisLineWidth = NULL, - pixelsPerLabel = NULL, axisLabelColor = NULL, axisLabelFontSize = NULL, - axisLabelWidth = NULL, axisLabelFormatter = NULL, valueFormatter = NULL, - drawGrid = NULL, gridLineColor = NULL, gridLineWidth = NULL, - independentTicks = NULL) +dyAxis(dygraph, name, label = NULL, valueRange = NULL, + logscale = NULL, ticker = NULL, rangePad = NULL, + labelWidth = NULL, labelHeight = NULL, axisHeight = NULL, + axisLineColor = NULL, axisLineWidth = NULL, pixelsPerLabel = NULL, + axisLabelColor = NULL, axisLabelFontSize = NULL, + axisLabelWidth = NULL, axisLabelFormatter = NULL, + valueFormatter = NULL, drawGrid = NULL, gridLineColor = NULL, + gridLineWidth = NULL, independentTicks = NULL) } \arguments{ \item{dygraph}{Dygraph to add an axis definition to} diff --git a/man/dyCrosshair.Rd b/man/dyCrosshair.Rd index a3a4539..bae3f8f 100644 --- a/man/dyCrosshair.Rd +++ b/man/dyCrosshair.Rd @@ -7,15 +7,16 @@ 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.} \usage{ -dyCrosshair(dygraph, direction = c("both", "horizontal", "vertical"), color=rgb(0,0,0,0.3)) +dyCrosshair(dygraph, direction = c("both", "horizontal", "vertical"), + color = rgb(0, 0, 0, 0.3)) } \arguments{ \item{dygraph}{Dygraph to add plugin to} \item{direction}{Crosshair direction. Valid options are: "both", "horizontal", "vertical"} - -\item{color}{Color and alpha (transparency) of crosshair} + +\item{color}{Crosshair color in RGB form ("#ff0088" or rgb(255,0,136)), default black and 0.3 alpha.} } \value{ Dygraph with Crosshair plugin enabled @@ -30,5 +31,6 @@ the "options" argument to dyPlugin. library(dygraphs) dygraph(ldeaths) \%>\% dyRangeSelector() \%>\% - dyCrosshair(direction = "vertical", color=rgb(1.0,0,0,0.5)) + dyCrosshair(direction = "vertical") + } diff --git a/man/dyGroup.Rd b/man/dyGroup.Rd index 1db362b..f9b7610 100644 --- a/man/dyGroup.Rd +++ b/man/dyGroup.Rd @@ -4,10 +4,10 @@ \alias{dyGroup} \title{dygraph series group} \usage{ -dyGroup(dygraph, name = NULL, label = NULL, color = NULL, axis = "y", - stepPlot = NULL, stemPlot = NULL, fillGraph = NULL, drawPoints = NULL, - pointSize = NULL, pointShape = NULL, strokeWidth = NULL, - strokePattern = NULL, strokeBorderWidth = NULL, +dyGroup(dygraph, name = NULL, label = NULL, color = NULL, + axis = "y", stepPlot = NULL, stemPlot = NULL, fillGraph = NULL, + drawPoints = NULL, pointSize = NULL, pointShape = NULL, + strokeWidth = NULL, strokePattern = NULL, strokeBorderWidth = NULL, strokeBorderColor = NULL, plotter = NULL) } \arguments{ diff --git a/man/dyOptions.Rd b/man/dyOptions.Rd index 4a25f79..5147d2e 100644 --- a/man/dyOptions.Rd +++ b/man/dyOptions.Rd @@ -6,22 +6,24 @@ \usage{ dyOptions(dygraph, stackedGraph = FALSE, fillGraph = FALSE, fillAlpha = 0.15, stepPlot = FALSE, stemPlot = FALSE, - drawPoints = FALSE, pointSize = 1, pointShape = c("dot", "triangle", - "square", "diamond", "pentagon", "hexagon", "circle", "star", "plus", "ex"), - drawGapEdgePoints = FALSE, connectSeparatedPoints = FALSE, - strokeWidth = 1, strokePattern = NULL, strokeBorderWidth = NULL, + drawPoints = FALSE, pointSize = 1, pointShape = c("dot", + "triangle", "square", "diamond", "pentagon", "hexagon", "circle", "star", + "plus", "ex"), drawGapEdgePoints = FALSE, + connectSeparatedPoints = FALSE, strokeWidth = 1, + strokePattern = NULL, strokeBorderWidth = NULL, strokeBorderColor = "white", plotter = NULL, colors = NULL, colorValue = 0.5, colorSaturation = 1, drawXAxis = TRUE, drawYAxis = TRUE, includeZero = FALSE, drawAxesAtZero = FALSE, logscale = FALSE, axisTickSize = 3, axisLineColor = "black", - axisLineWidth = 0.3, axisLabelColor = "black", axisLabelFontSize = 14, - axisLabelWidth = 60, drawGrid = TRUE, gridLineColor = NULL, - gridLineWidth = 0.3, titleHeight = NULL, rightGap = 5, - digitsAfterDecimal = 2, labelsKMB = FALSE, labelsKMG2 = FALSE, - labelsUTC = FALSE, maxNumberWidth = 6, sigFigs = NULL, - panEdgeFraction = NULL, animatedZooms = FALSE, - mobileDisableYTouch = TRUE, timingName = NULL, useDataTimezone = FALSE, - retainDateWindow = FALSE, disableZoom = FALSE) + axisLineWidth = 0.3, axisLabelColor = "black", + axisLabelFontSize = 14, axisLabelWidth = 60, drawGrid = TRUE, + gridLineColor = NULL, gridLineWidth = 0.3, titleHeight = NULL, + rightGap = 5, digitsAfterDecimal = 2, labelsKMB = FALSE, + labelsKMG2 = FALSE, labelsUTC = FALSE, maxNumberWidth = 6, + sigFigs = NULL, panEdgeFraction = NULL, animatedZooms = FALSE, + mobileDisableYTouch = TRUE, timingName = NULL, + useDataTimezone = FALSE, retainDateWindow = FALSE, + disableZoom = FALSE) } \arguments{ \item{dygraph}{Dygraph to add options to} diff --git a/man/dyRangeSelector.Rd b/man/dyRangeSelector.Rd index 8e498ed..2a816f8 100644 --- a/man/dyRangeSelector.Rd +++ b/man/dyRangeSelector.Rd @@ -5,8 +5,8 @@ \title{dygraph interactive range selection and zooming} \usage{ dyRangeSelector(dygraph, dateWindow = NULL, height = 40, - fillColor = " #A7B1C4", strokeColor = "#808FAB", keepMouseZoom = TRUE, - retainDateWindow = FALSE) + fillColor = " #A7B1C4", strokeColor = "#808FAB", + keepMouseZoom = TRUE, retainDateWindow = FALSE) } \arguments{ \item{dygraph}{Dygraph to add range selector to} diff --git a/man/dyRibbon.Rd b/man/dyRibbon.Rd index 0ffd218..dadb6ec 100644 --- a/man/dyRibbon.Rd +++ b/man/dyRibbon.Rd @@ -7,8 +7,8 @@ can be useful to visualize categorical variables (http://en.wikipedia.org/wiki/Categorical_variable) that change over time (along the x-axis).} \usage{ -dyRibbon(dygraph, data = NULL, palette = NULL, parser = NULL, top = 1, - bottom = 0) +dyRibbon(dygraph, data = NULL, palette = NULL, parser = NULL, + top = 1, bottom = 0) } \arguments{ \item{dygraph}{Dygraph to add plugin to} diff --git a/man/dySeries.Rd b/man/dySeries.Rd index cd949f0..b993187 100644 --- a/man/dySeries.Rd +++ b/man/dySeries.Rd @@ -4,10 +4,10 @@ \alias{dySeries} \title{dygraph data series} \usage{ -dySeries(dygraph, name = NULL, label = NULL, color = NULL, axis = "y", - stepPlot = NULL, stemPlot = NULL, fillGraph = NULL, drawPoints = NULL, - pointSize = NULL, pointShape = NULL, strokeWidth = NULL, - strokePattern = NULL, strokeBorderWidth = NULL, +dySeries(dygraph, name = NULL, label = NULL, color = NULL, + axis = "y", stepPlot = NULL, stemPlot = NULL, fillGraph = NULL, + drawPoints = NULL, pointSize = NULL, pointShape = NULL, + strokeWidth = NULL, strokePattern = NULL, strokeBorderWidth = NULL, strokeBorderColor = NULL, plotter = NULL) } \arguments{ diff --git a/man/dyUpdate.Rd b/man/dyUpdate.Rd index ce6643e..e75864b 100644 --- a/man/dyUpdate.Rd +++ b/man/dyUpdate.Rd @@ -1,28 +1,64 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plugins.R -\name{dyUnzoom} -\alias{dyUnzoom} -\title{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).} +% Please edit documentation in R/update.R +\name{dyUpdate} +\alias{dyUpdate} +\title{dyUpdate allows in-situ replacement of the rendered timeseries in dygraph within shiny, rather than +rerendering the widget on each data change. This can be used for "real-time" update changes in +sampling, etc.} \usage{ -dyUnzoom(dygraph) +dyUpdate(session, id, data) } \arguments{ -\item{dygraph}{Dygraph to add plugin to} -} -\value{ -Dygraph with Unzoom plugin enabled +\item{session}{shiny session} + +\item{id}{graph identifier (refers to the dygraph elementId parameter)} + +\item{data}{the latest data set to be rendered (must have the same number of columns as the original data set)} } \description{ -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). +dyUpdate allows in-situ replacement of the rendered timeseries in dygraph within shiny, rather than +rerendering the widget on each data change. This can be used for "real-time" update changes in +sampling, etc. +} +\note{ +See the \href{https://rstudio.github.io/dygraphs/}{online documentation} for +additional details and examples. } \examples{ -library(dygraphs) -dygraph(ldeaths) \%>\% - dyRangeSelector() \%>\% - dyUnzoom() +require(shiny) +require(dygraphs) + +app = function () { + newdata <- function(n = 1000) { + vclose <- cumsum(rnorm(n,sd=0.25)) + vlow <- vclose - abs(rnorm(n,sd=0.25)) + vhigh <- vclose + abs(rnorm(n,sd=0.25)) + vopen <- c(vlow[1], vclose[1:(NROW(vclose)-1)]) + times <- as.POSIXct((1:n)*5, origin='2018-1-1 00:00:00', tz='UTC') + data.frame(open=vopen, high=vhigh, low=vlow, close=vclose, row.names = times) + } + graph = function() { + bars <- newdata() + v1 <- dygraph(bars, height=650, width='100\%', elementId='graph1') \%>\% + dyCandlestick() \%>\% + dyOptions(labelsUTC = TRUE) + htmltools::browsable(v1) + } + + ui <- fluidPage( + sidebarLayout(sidebarPanel(actionButton("button", "regenerate")), + mainPanel(graph()))) + + events <- function (input, output, session) { + observeEvent(input$button, { + bars <- newdata() + dyUpdate (session, 'graph1', bars) + }) + } + + shinyApp(ui = ui, server = events, options=list(port=5432, host="127.0.0.1")) +} + +app() } diff --git a/man/dygraph.Rd b/man/dygraph.Rd index f17d245..522f461 100644 --- a/man/dygraph.Rd +++ b/man/dygraph.Rd @@ -4,8 +4,9 @@ \alias{dygraph} \title{dygraph interactive plot for time series data} \usage{ -dygraph(data, main = NULL, xlab = NULL, ylab = NULL, periodicity = NULL, - group = NULL, elementId = NULL, width = NULL, height = NULL) +dygraph(data, main = NULL, xlab = NULL, ylab = NULL, + periodicity = NULL, group = NULL, elementId = NULL, width = NULL, + height = NULL) } \arguments{ \item{data}{Either time series data or numeric data. For time series, this