#' Plots Aw
#'
#'
#' @param bluQAwInput Aw JSON file input
#' @return HTML plot of Aw result ("bluQPlotAw.html")
#' @import widgetframe
#' @import htmlwidgets
#' @import jsonlite
#' @import scales
#' @import ggplot2
#' @import plotly
#' @examples
#' bluQPlotAwJsonFile(system.file("extdata","Aw_sample.json",package="bluQPlotAw"))
#' @export
bluQPlotAwJsonFile <- function(bluQAwInput) {
df1<- jsonlite::fromJSON(bluQAwInput, flatten=TRUE)
df1$Timestamp<-as.POSIXct(df1$Timestamp)
Aw<-as.numeric(df1$Value)
Timestamp<-df1$Timestamp
ggp <- ggplot2::ggplot(data=df1,
aes(x=Timestamp, y=Aw, group=1, colour=Aw,
text=paste( 'Product: ',df1$Product,'\n',
'SampleID: ',df1$SampleID,'\n',
'BatchID: ',df1$BatchID,'\n',
'LotID: ',df1$LotID,'\n',
'Timestamp: ',Timestamp,'\n',
'Water Activity: ',Aw, '\n')))+
ggplot2::geom_point(size=2)+
ggplot2::geom_line(color='deepskyblue3') +
ggplot2::scale_x_datetime(labels = scales::date_format("%b-%d-%Y"))+
ggplot2::theme(axis.text.x = element_text(angle = 90, hjust = 1))+
ggplot2::geom_hline(yintercept=0.6,color='deepskyblue4', size=0.2)+
ggplot2::scale_y_continuous(breaks = scales::pretty_breaks(n = 10),limits = c(0, 1))+
ggplot2::scale_colour_gradient2( limits = c(0, 1),
midpoint=0.6, low="#0072B2",mid = "#0072B2",
high="violet", space ="Lab")
ggpl <- plotly::ggplotly(ggp, tooltip = 'text')
htmlwidgets::saveWidget(widgetframe::frameableWidget(ggpl),'bluQPlotAw.html')
#rawhtml <- readBin('bluQPlotAw.html', raw(), file.info('bluQPlotAw.html')$size)
#return(rawhtml)
#data <- readLines('bluQPlotAw.html')
#return(list(text = paste(data, collapse = "\n")))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.