OliverKeyes has submitted this change and it was merged.

Change subject: Adds steps for dealing with bad data - Cleans data before 
passing it to xts - Adds na_box for cases where value could not be calculated
......................................................................


Adds steps for dealing with bad data
- Cleans data before passing it to xts
- Adds na_box for cases where value could not be calculated

Change-Id: I7f1035cf5bc0f55533fb89eba3de72b000d69eab
---
M NAMESPACE
M R/dygraphs.R
M R/shiny.R
M man/check_notify.Rd
M man/cond_color.Rd
M man/cond_icon.Rd
A man/na_box.Rd
M man/time_frame_range.Rd
8 files changed, 55 insertions(+), 10 deletions(-)

Approvals:
  OliverKeyes: Verified; Looks good to me, approved



diff --git a/NAMESPACE b/NAMESPACE
index 1c33233..62e89ca 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -12,6 +12,7 @@
 export(half)
 export(mad)
 export(make_dygraph)
+export(na_box)
 export(percent_change)
 export(read_dataset)
 export(safe_tail)
@@ -37,5 +38,6 @@
 importFrom(readr,read_delim)
 importFrom(shiny,icon)
 importFrom(shinydashboard,notificationItem)
+importFrom(shinydashboard,valueBox)
 importFrom(xts,xts)
 importFrom(zoo,rollmean)
diff --git a/R/dygraphs.R b/R/dygraphs.R
index ef018ef..5d9497c 100644
--- a/R/dygraphs.R
+++ b/R/dygraphs.R
@@ -32,8 +32,13 @@
   # Make sure we're not dealing with tbl_df or data.table nonsense
   class(data) <- "data.frame"
 
+  # If something has gone really awry and we get a <NA> as a date, xts will 
return an error:
+  #   "Error in xts::periodicity(data) : can not calculate periodicity of 1 
observation"
+  #   So let's sanitize before we run xts.
+  data <- data[!is.na(data[[1]]), ]
+
   # If we've only got a single variable reformatting into an XTS looks weird, 
but otherwise we're
-  # all cool.
+  #   all cool.
   if (ncol(data) == 2) {
     if (is.null(legend_name)) {
       legend_name <- names(data)[2]
@@ -44,7 +49,7 @@
     data <- xts::xts(data[,-1], order.by = data[[1]])
   }
 
-  # Construct and return the dygraph
+  # Construct and return the dygraph.
   return(dygraph(data, main = title, xlab = xlab, ylab = ylab, group = group) 
%>%
            dyLegend(width = 400, show = "always") %>%
            dyOptions(strokeWidth = 3,
diff --git a/R/shiny.R b/R/shiny.R
index 3aefbb3..cc90596 100644
--- a/R/shiny.R
+++ b/R/shiny.R
@@ -83,3 +83,15 @@
                 quarter = c(Sys.Date()-91, Sys.Date()-1),
                 custom = input_local_daterange))
 }
+
+#'@title Bad Data Value Box
+#'@description This is used in cases where something has gone wrong with the
+#'  data and a value could not be calculated. This ensures the "bad data" value
+#'  boxes have a consistent look.
+#'@param subtitle Subtitle text.
+#'@family Shiny Dashboarding
+#'@importFrom shinydashboard valueBox
+#'@export
+na_box <- function(subtitle) {
+  return(valueBox(subtitle = subtitle, value = "NA", color = "red", icon = 
icon("warning")))
+}
diff --git a/man/check_notify.Rd b/man/check_notify.Rd
index ca285dd..7554fc1 100644
--- a/man/check_notify.Rd
+++ b/man/check_notify.Rd
@@ -21,7 +21,8 @@
  detected.
 }
 \seealso{
-Other Shiny.Dashboarding: \code{\link{cond_color}},
-  \code{\link{cond_icon}}, \code{\link{time_frame_range}}
+Other Shiny Dashboarding: \code{\link{cond_color}},
+  \code{\link{cond_icon}}, \code{\link{na_box}},
+  \code{\link{time_frame_range}}
 }
 
diff --git a/man/cond_color.Rd b/man/cond_color.Rd
index d0f1ba6..5c51ceb 100644
--- a/man/cond_color.Rd
+++ b/man/cond_color.Rd
@@ -18,7 +18,8 @@
 Uses green as the "true" colour by default, "red" as false, and
 }
 \seealso{
-Other Shiny.Dashboarding: \code{\link{check_notify}},
-  \code{\link{cond_icon}}, \code{\link{time_frame_range}}
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_icon}}, \code{\link{na_box}},
+  \code{\link{time_frame_range}}
 }
 
diff --git a/man/cond_icon.Rd b/man/cond_icon.Rd
index 0706d6c..be1f658 100644
--- a/man/cond_icon.Rd
+++ b/man/cond_icon.Rd
@@ -17,7 +17,8 @@
  change in condition.
 }
 \seealso{
-Other Shiny.Dashboarding: \code{\link{check_notify}},
-  \code{\link{cond_color}}, \code{\link{time_frame_range}}
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_color}}, \code{\link{na_box}},
+  \code{\link{time_frame_range}}
 }
 
diff --git a/man/na_box.Rd b/man/na_box.Rd
new file mode 100644
index 0000000..7dc9a96
--- /dev/null
+++ b/man/na_box.Rd
@@ -0,0 +1,22 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/shiny.R
+\name{na_box}
+\alias{na_box}
+\title{Bad Data Value Box}
+\usage{
+na_box(subtitle)
+}
+\arguments{
+\item{subtitle}{Subtitle text.}
+}
+\description{
+This is used in cases where something has gone wrong with the
+ data and a value could not be calculated. This ensures the "bad data" value
+ boxes have a consistent look.
+}
+\seealso{
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_color}}, \code{\link{cond_icon}},
+  \code{\link{time_frame_range}}
+}
+
diff --git a/man/time_frame_range.Rd b/man/time_frame_range.Rd
index 8dc51ac..1b1635d 100644
--- a/man/time_frame_range.Rd
+++ b/man/time_frame_range.Rd
@@ -37,7 +37,8 @@
 \seealso{
 \code{\link{subset_by_date_range}}
 
-Other Shiny.Dashboarding: \code{\link{check_notify}},
-  \code{\link{cond_color}}, \code{\link{cond_icon}}
+Other Shiny Dashboarding: \code{\link{check_notify}},
+  \code{\link{cond_color}}, \code{\link{cond_icon}},
+  \code{\link{na_box}}
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/264780
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7f1035cf5bc0f55533fb89eba3de72b000d69eab
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/polloi
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>
Gerrit-Reviewer: OliverKeyes <oke...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to