In [2]:
library(visualizeR)

In [8]:
data("coffeeNMRSpectra")

ID <- coffeeNMRSpectra$param$catalogID
group <- coffeeNMRSpectra$param$country1
metadata <- data.frame( sapply(coffeeNMRSpectra$param, function(x) x) )
x <- matrix(sapply(I(as.matrix(coffeeNMRSpectra$nmr)), function(x) x), 34, 1610)
x_axis <- as.numeric( colnames(coffeeNMRSpectra$nmr) )


d = list()
c <- data.frame(ID = ID,
                group = group,
                color = sapply(group, function(x) getColor2(as.character(x))), # can be made faster using levels
                "_hightlight" = seq_along(group),
                dataMatrix = I(matrix( c(rbind(repRow(x_axis, nrow(x)), x)), nrow(x), ncol(x)*2)),
                I(metadata),
                check.names = FALSE
)
d <- appendData(data = d, variableName = "data", variable = c, type = "table")

b <- simplify2array( by(x, group, function(x) apply(x, 2, mean)) )

for (i in levels(group)) {
  var <- data.frame(y =  as.numeric(b[,i]), x = x_axis)
  d <- appendData(data = d, variableName = paste0("mean",i), variable = var, type = "1D XY array")
}

var <- data.frame(y = apply(x, 2, min), x = x_axis)
d <- appendData(data = d, variableName = "minSpectra", variable = var, type = "1D XY array")
var <- data.frame(y = apply(x, 2, max), x = x_axis)
d <- appendData(data = d, variableName = "maxSpectra", variable = var, type = "1D XY array")

imag = NULL
for (i in seq(from=2, to=3220, by=2)) {
  png(tf1 <- tempfile(fileext = ".png"));  boxplot( dataMatrix[,i] ~ group, data = c); dev.off()
  imag[[i/2]] <- paste0("data:image/png;base64,", base64enc::base64encode(tf1))#base64enc::base64encode(tf1)
}
l <- data.frame("_hightlight" = seq_along(x_axis),
                #value = paste0("data:image/png;base64,", base64enc::base64encode(tf1)),
                value = unlist(imag),
                check.names = FALSE)
d <- appendData(data = d, variableName = "img", variable = l, type = "table")

# library(ggplot2)
# means <- aggregate(dataMatrix[,i] ~  group, c, mean)
# names(means) <- c("group", "dataMatrix")
# ggplot(data=c, aes(x=group, y=dataMatrix[,i], fill=group)) + geom_boxplot() +
#   stat_summary(fun.y=mean, colour="darkred", geom="point",
#                shape=18, size=3,show.legend = FALSE) +
#   geom_text(data = means, aes(label = round(dataMatrix,1), y = dataMatrix * 1.15))

varQuantile <- apply(x,2,quantile)
quantileData <- data.frame(
  value = as.numeric(t(varQuantile)),
  check.names = FALSE)
d <- appendData(data = d, variableName = "quantile", variable = quantileData, type = "table")

In [12]:
v <- new("visualization")
v@view <- "spectraExplorer.view.json"
v@data <- "spectraExplorer.data.json"
push(v, type="data", d)
print(v)


'http://127.0.0.1:5474/?viewURL=http://127.0.0.1:5474/view/spectraExplorer.view.json&dataURL=http://127.0.0.1:5474/data/spectraExplorer.data.json'

In [13]:
visualize(v)


Error in startServer(host, port, app): Failed to create server
Traceback:

1. visualize(v)
2. visualize(v)   # at line 17 of file /home/jul/git/visualizeR/R/visualize.R
3. initServer(v@visuServer, force = FALSE)   # at line 20 of file /home/jul/git/visualizeR/R/visualize.visualization.R
4. servr::httw(dir = server@rootDir, watch = server@rootDir, port = server@port)   # at line 26-28 of file /home/jul/git/visualizeR/R/initServer.R
5. dynamic_site(dir, ..., build = watch_dir(watch, pattern = pattern, 
 .     all_files = all_files, handler = handler))
6. res$start_server(app)
7. startServer(host, port, app)
8. stop("Failed to create server")

In [ ]:


In [ ]: