dySliderInput plugin and minor bug fix #135
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dySliderInput
Overview
This pull request includes a
dySliderInput
plugin that turns dygraphs into a slider input widget. Check out this online demo at shinyapps.io. Dygraphs offers great potential for many plugins and I think it would be great if these were all available from this package so that users can easily access them. To that end, I have added functions for this plugin and the other plugins (dyUnzoom
anddyCrosshair
) so that users can use these plugins. It also fixes a bug in returning date-times from dygraphs.How does dySliderInput work?
I have written a dygraphs plugin called
dySliderInput
in javascript. This plugin can be compiled using thedyPlugin
function and added to an existingdygraph
object. Once added to adygraph
object, users can click on the dygraph and a bar will be added to mark closest data point (which can be accessed programatically usinginput$dygraph_click$date
). Additionally, users can animate the slider bar by clicking on the play button. The animation can be customised similar to that inshiny::sliderInput
using theshiny::animationOptions
function. This plugin is best used when in conjunction with other widgets. For instance, it could be used with the leaflet R package to show spatio-temporal data (as shown in the demo). This plugin is compatible with thedyRangeSelector
. I have included the above demo as an example in the package.Proposed usage of dySliderInput
List of changes
Here I will list all the changes I have made to this package, and my rationale behind them.
dySliderInput
NAMESPACE
: Now includes thedySliderInput
function and functions it uses in other packages (grDevices::col2rgb
,shiny::icon
, andshiny::animationOptions
).DESCRIPTION
: ThedySliderInput
function uses theanimationOptions
andicon
functions from shiny. Thus I have added 'shiny' to the imports section of the package. Additionally, becausedevtools::check()
does not allow packages to listed under imports and enchances, I have removed shiny from enhances.R/plugins.R
: I have added thedySliderInput
function to allow users to add this plugin.tests/testthat/test-slider-input.R
: This provides a test for thedySliderInput
function.inst/examples/shiny_2
: I have added the code for thedySliderInput
demo here.inst/examples/plugins/sliderinput.js
: This include the code for thedySliderInput
plugin.Bug fix
inst/htmlwidgets/dygraphs.js
:input$dygraph_click
andinput$dygraph_date_window
variables in a shiny session. The variables are based on a call tonew Date(x)
in javascript. However, just returning this can cause the returned dates to be incorrect.Date
object. To do this, I have included ashinyValueFormatter
function that uses the function that generates x-axis labels (xValueFormatterFixedTZ
orxValueFormatter
) to correctly parse the string.xValueFormatter
originally made a call toDate().toLocaleString
which uses different date-time formats depending on the environment, I have changed this to manually parse the same date-time format returned fromxValueFormatterFixedTZ
(but without the time-zone information).DyUnzoom and dyCrosshair functions
NAMESPACE
: Now includes thedygraphs::dyCrosshair
,dygraphs::dyUnzoom
functions.R/plugins.R
: I have added thedyCrosshair
,dyUnzoom
functions to allow users to add these plugins.tests/testthat/test-crosshair.R
: This provides a test for thedyCrosshair
function.tests/testthat/test-unzoom.R
: This provides a test for thedyUnzoom
function.Miscellaneous
I really would like to see the
dySliderInput
widget incorporated into the dygraphs R package, so please let me know if you disagree with any of these changes, and I will update my PR accordingly.