R/bluQPlotPEPjson.R

#' Plots PEP
#'
#'
#' @param bluQPEPinput PEP JSON input
#' @return HTML plot of PEP result ("bluQPlotPEP.html")
#' @import widgetframe
#' @import htmlwidgets
#' @import jsonlite
#' @import scales
#' @import ggplot2
#' @import plotly
#' @examples
#' bluQPlotPEPjson(jsonlite::fromJSON(system.file("extdata","PEP_sample.json",package="bluQPlotPEP")))
#' @export
bluQPlotPEPjson <- function(bluQPEPinput) {

  df1<- bluQPEPinput
  
  df1$Timestamp<-as.POSIXct(df1$Timestamp)
  PEPresult<-as.numeric(df1$Result)
  Timestamp<-df1$Timestamp
  ggp <- ggplot2::ggplot(data=df1, aes(x=df1$Timestamp, y=df1$Result, group=1, text=paste('Plant: ',df1$Plant,'\n',
                                                                     'SampleID: ',df1$SampleID,'\n',
                                                                     'BatchID: ',df1$BatchID,'\n',
                                                                     'LotID: ',df1$LotID,'\n',
                                                                     'Timestamp: ',Timestamp,'\n',
                                                                     'PEP Result: ',PEPresult, '\n'))) +
    ggplot2::scale_colour_manual(name="",  values =c("violet","#0072B2"))+
    ggplot2::geom_point(aes(colour=df1$Result), size=4) +
    ggplot2::geom_point(aes(shape=df1$Plant), size=2) +
    ggplot2::theme(legend.title = element_blank()) +
    ggplot2::geom_line(color='deepskyblue3') +
    ggplot2::theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
    ggplot2::scale_x_datetime(labels = scales::date_format("%b-%d-%Y"))

  ggpl <- plotly::ggplotly(ggp, tooltip = 'text')
  htmlwidgets::saveWidget(widgetframe::frameableWidget(ggpl),'bluQPlotPEP.html',selfcontained=TRUE)
  #rawhtml <- readBin('bluQPlotPEP.html', raw(), file.info('bluQPlotPEP.html')$size)
  #return(rawhtml)
  #data <- readLines('bluQPlotPEP.html')
  #return(list(text = paste(data, collapse = "\n")))
}
mjmg/bluQPlotPEP documentation built on May 27, 2019, 8:46 a.m.