Commit 710f350e authored by Stephanie Wegscheidl's avatar Stephanie Wegscheidl

Multiple charts working, Importing Packages updated and Strucutred Code

parent a5a702bd
......@@ -192,339 +192,407 @@ server <- function(input, output, session) {
#Title Input
output$title <- renderText({ input$title })
#BARCHART selectinputs
output$input_hist_x <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("bar_x", "x-axis:", choices = colnames(coconut.df))
})
output$input_hist_y <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("bar_y", "y-axis:", choices = colnames(coconut.df))
})
#TIMELINE selectinput--> do not need it
# output$input_time_data <- renderUI({
# #BARCHART selectinputs
# output$input_hist_x <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("bar_x", "x-axis:", choices = colnames(coconut.df))
# })
#
# output$input_hist_y <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("bar_y", "y-axis:", choices = colnames(coconut.df))
# })
#
#
# #TIMELINE selectinput--> do not need it
#
# # output$input_time_data <- renderUI({
# # if (is.null(input$nut))
# # return(NULL)
# # selectInput("input_time_data", "x-axis:", choices = colnames(coconut.df))
# # })
# #
# # output$input_time_y <- renderUI({
# # if (is.null(input$nut))
# # return(NULL)
# # selectInput("in4", "y-axis:", cbind("unixTime", "longitude", "latitude", "speed", "gps.acc","lux", "light.acc","acc.coordinates", "acc.acc","bluetooth","ble.bpm","ble.bpmlist","ble.hrv","ble.hrvlist","activity.name", "acctivity.confidence","screen.status" ,"touch"),multiple=TRUE, selectize=TRUE)
# # })
#
# #LINECHART selectinput x
# output$input_line_x <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("input_time_data", "x-axis:", choices = colnames(coconut.df))
# selectInput("line_x", "x-axis", choices=colnames(coconut.df))
# })
#
# output$input_time_y <- renderUI({
# #LINECHART selectinput y
# output$input_line_y <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("in4", "y-axis:", cbind("unixTime", "longitude", "latitude", "speed", "gps.acc","lux", "light.acc","acc.coordinates", "acc.acc","bluetooth","ble.bpm","ble.bpmlist","ble.hrv","ble.hrvlist","activity.name", "acctivity.confidence","screen.status" ,"touch"),multiple=TRUE, selectize=TRUE)
# selectInput("line_y", "y-axis", choices=colnames(coconut.df)) })
#
#
# #SCATTERPLOT selectinput x
# output$input_scat_x <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("scat_x", "x-axis", choices=colnames(coconut.df))
# })
#
# #SCATTERPLOT selectinput y
# output$input_scat_y <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("scat_y", "y-axis", choices=colnames(coconut.df))
# })
#
# #BOXPLOT selectinput x
# output$input_box_x <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("box_x", "data", choices=colnames(coconut.df))
# })
#
# #BOXPLOT selectinput y
# output$input_box_y <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("box_y", "y-axis", choices=colnames(coconut.df))
# })
#
#
# #MAP selectinput
# output$input_map <- renderUI({
# if (is.null(input$nut))
# return(NULL)
# selectInput("map_data", "data", choices=colnames(coconut.df))
# })
#LINECHART selectinput x
output$input_line_x <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("line_x", "x-axis", choices=colnames(coconut.df))
})
#LINECHART selectinput y
output$input_line_y <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("line_y", "y-axis", choices=colnames(coconut.df)) })
#SCATTERPLOT selectinput x
output$input_scat_x <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("scat_x", "x-axis", choices=colnames(coconut.df))
})
#SCATTERPLOT selectinput y
output$input_scat_y <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("scat_y", "y-axis", choices=colnames(coconut.df))
})
#BOXPLOT selectinput x
output$input_box_x <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("box_x", "data", choices=colnames(coconut.df))
})
#BOXPLOT selectinput y
output$input_box_y <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("box_y", "y-axis", choices=colnames(coconut.df))
})
#MAP selectinput
output$input_map <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("map_data", "data", choices=colnames(coconut.df))
})
#Continue to dashboard page
observeEvent(input$dashboardSite, {
updateTabItems(session, "tabs",selected = "dashboard")
})
#For counting the plots and giving axis and plots individual names
plotCounter <<- 0
plotname <<- paste("plot", plotCounter, sep="")
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
#TODO: Multiple charts. ADD BARCHART BUTTON
#BARCHART box insert
observeEvent(input$check_hist, {
#Setting names
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
print(plotCounter)
print(plotname)
#Inserting box & Chart
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Barchart",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
#print(xplotname),
plotOutput(plotname, height = 250))
selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
plotOutput(plotname, height = 400))
)
local({
# data handling
output[[plotname]] <- renderPlot({
print("hello itse mi")
print(yplotname)
data<- structure(list(V1=as.numeric(coconut.df[[input[[xplotname]]]]),
V2=as.numeric(coconut.df[[input[[yplotname]]]])),
.Names=c("V1","V2"), row.names=c(NA,10L), class = "data.frame")
#print("data")
#print(data)
#Neues Plot
barplot(data$V2,data$V1,
ylab= yplotname,
xlab=xplotname)
# New Bar-Plot
barplot(data$V2,data$V1,
ylab=input[[yplotname]],
xlab=input[[xplotname]],
names.arg = data$V1
# NOTE: PLEASE COMMENT IN IF DATA SET WITH FEW DATA IS USED --> MAKES AXES BETTER READABLE
#,
#las=2
#axis.lty=1
)
})
}) #Local end
})
#BARCHART view
## ALTES PLOT
#a=1
#for(a in 1:length(coconut.df$bluetooth.numOfBTDevices)){
#g <-geom_bar(mapping = NULL, data = , stat = "count",
# position = "stack", width = NULL, binwidth = NULL, na.rm = FALSE,
# show.legend = NA, inherit.aes = TRUE)
#g <- ggplot(coconut.df, aes("timestamp","bluetooth"))
#g + geom_bar()
# a=a+1}
#g
#hist(bluetooth)
#BARCHART text
output$bar_explain <- renderText({
"Select data for the x- and y-axis then go to add barchart if you want this data to be visualized in a barchart."
})
#TIMELINE insert box
output$time_box <- renderUI({
if(input$check_time)
box( width = 12,
title="Timeline",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
timevisOutput("time", height = 175)
)
"Here you can add a barchart. A bar chart uses bars to show comparisons between categories of data. If you was trying to compare the height of something then intuitvely you would represent this by using columns. After clicking on the add button, a box with dropdownfields and a barchart will apear. Please set your wanted data for the x-and y-axis. Also be aware, that once you created another chart you won't be able to change the data of your previous charts."
})
#TIMELINE view
output$time <- renderTimevis({
print("TIME wird aufgerufen")
observeEvent(input$check_time, {
print("Length:")
print(length(parsedEndtimes))
print("combined")
print( c(anytime(totalST), head(parsedEndtimes, -1)))
print("endtimes")
print(parsedEndtimes)
data <- data.frame(
id = 1:length(parsedEndtimes),
content= c(1:length(parsedEndtimes)),
start = c(anytime(totalST), head(parsedEndtimes, -1)),
end = parsedEndtimes
# plotname<<-paste("plot", plotCounter, sep="")
# plotCounter<<-plotCounter+1
# xplotname<<- paste("x",plotname,sep="")
# yplotname<<-paste("y",plotname, sep="")
insertUI(
#Inserting box and Chart
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Timeline",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
timevisOutput("time", height = 250))
)
timevis(data)
local({
output$time <- renderTimevis({
# data handling
data <- data.frame(
id = 1:length(parsedEndtimes),
content= c(1:length(parsedEndtimes)),
start = c(anytime(totalST), head(parsedEndtimes, -1)),
end = parsedEndtimes
)
#New Timeline
timevis(data)
})
})
})
# #TIMELINE insert box
# output$time_box <- renderUI({
# if(input$check_time)
# box( width = 12,
# title="Timeline",
# status= "warning",
# solidHeader = TRUE,
# collapsible = TRUE,
# timevisOutput("time", height = 175)
# )
# })
#
# #TIMELINE view
# output$time <- renderTimevis({
# print("TIME wird aufgerufen")
#
# print("Length:")
# print(length(parsedEndtimes))
# print("combined")
# print( c(anytime(totalST), head(parsedEndtimes, -1)))
# print("endtimes")
# print(parsedEndtimes)
#
#
# data <- data.frame(
# id = 1:length(parsedEndtimes),
# content= c(1:length(parsedEndtimes)),
# start = c(anytime(totalST), head(parsedEndtimes, -1)),
# end = parsedEndtimes
# )
# timevis(data)
#
# })
#TIMELINE text
output$texttimeline <- renderText({
"Add Timeline for getting a Timeline about CoCoQuest Tasks and Questions.To see how long a the participant took for a certain task."
})
#LINECHART insert box
output$line_box <- renderUI({
if(input$check_line)
box( width = 12,
title="Linechart",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
#add_tooltip(data_tooltip, "hover"),
line_plot<<-plotOutput("line", height = 250))
"Add Timeline for getting a Timeline about CoCoQuest Tasks and Questions.To see how long a the participant took for a certain task. Please note that the timeline is static, you can not show different types of data here. Also you can not add multiple charts here. "
})
#LINECHART view
output$line <- renderPlot({
print("LINE wird aufgerufen")
data<- structure(list(V1=as.numeric(coconut.df[[input$line_x]]),
V2=as.numeric(coconut.df[[input$line_y]])),
.Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
print(data)
plot(data$V1,data$V2, type="l", ylab=input$line_y, xlab=input$line_x)
#LINECHART
observeEvent(input$check_line, {
#setting names
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
#inserting box and chart
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Linechart",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
plotOutput(plotname, height = 250))
)
local({
output[[plotname]] <- renderPlot({
#data handling
data<- structure(list(V1=as.numeric(coconut.df[[input[[xplotname]]]]),
V2=as.numeric(coconut.df[[input[[yplotname]]]])),
.Names=c("V1","V2"), row.names=c(NA,10L), class = "data.frame")
#new Linechart
plot(data$V1,data$V2, type="l", ylab=input[[yplotname]], xlab=input[[xplotname]], las=2)
})
}) #Local end
})
#LINECHART text
output$line_explain <- renderText({
"Select data for the x- and y-axis then go to add linechart if you want this data to be visualized in a linechart."
"Here you can add a linechart. After clicking on the add button, a box with dropdownfields and a linechart will apear. Please set your wanted data for the x-and y-axis. Also be aware, that once you created another chart you won't be able to change the data of your previous charts."
})
#SCATTERPLOT insert box
output$scat_box <- renderUI({
if(input$check_scat)
box( width = 12,
title="Scatterplot",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
scat_plot<<- plotOutput("scat", height = 250))
#SCATTERPLOT
observeEvent(input$check_scat, {
#Setting names
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
# Inserting Box and Plot
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Scatterplot",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
plotOutput(plotname, height = 250))
)
local({
output[[plotname]] <- renderPlot({
print("hello itse mi")
print(yplotname)
#data handling
data<- structure(list(V1=as.numeric(coconut.df[[input[[xplotname]]]]),
V2=as.numeric(coconut.df[[input[[yplotname]]]])),
.Names=c("V1","V2"), row.names=c(NA,10L), class = "data.frame")
#new scatterplot
plot(data$V1,data$V2, type="p", ylab=input[[yplotname]], xlab=input[[xplotname]], las=2, axis.lty=1)
})
}) #Local end
})
#SCATTERPLOT view
output$scat <- renderPlot({
data<- structure(list(V1=as.numeric(coconut.df[[input$scat_x]]),
V2=as.numeric(coconut.df[[input$scat_y]])),
.Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
print("SCAT wird aufgerufen")
plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )
})
#SCATTERPLOT text
output$scat_explain <- renderText({
"Select data for the x- and y-axis then go to add scatterplot if you want this data to be visualized in a scatterplot."
"Here you can add a scatterplot. After clicking on the add button, a box with dropdownfields and a scatterolot will apear. Please set your wanted data for the x-and y-axis. Also be aware, that once you created another chart you won't be able to change the data of your previous charts."
})
#BOXPLOT insert box
output$box_box <- renderUI({
if(input$check_box)
box( width = 12,
title="Boxplot",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
box_plot<<- plotOutput("box", height = 250))
})
#BOXPLOT view
#TODO:scaling
output$box <- renderPlot({
print("BOX wird aufgerufen")
data<- structure(list(V1=as.numeric(coconut.df[[input$box_x]])),
.Names=c("V1"), row.names=c(NA,6L), class = "data.frame")
boxplot(data$V1, type="box", xlab=input$box_x )
#BOXPLOT
observeEvent(input$check_box, {
#Setting names
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
#Inserting Box and plot
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Boxplot",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
selectInput(xplotname, "data", choices=colnames(coconut.df)),
#selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
plotOutput(plotname, height = 250))
)
local({
output[[plotname]] <- renderPlot({
#handling data
data<- structure(list(V1=as.numeric(coconut.df[[input[[xplotname]]]])),
.Names=c("V1"), row.names=c(NA,10L), class = "data.frame")
#new Boxplot
boxplot(data$V1, type="box", xlab=input[[xplotname]])
})
}) #Local end
})
#BOXPLOT text
output$box_explain <- renderText({
"Select data then go to add boxplot if you want this data to be visualized in a boxplot."
})
#MAP insert box
output$map_box <- renderUI({
if(input$check_map)
box( width = 12,
title="Map",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
map_plot<<-leafletOutput("map", height = 250))
"Here you can add a boxplot. After clicking on the add button, a box with a dropdownfield and a boxplot will apear. Please set your wanted data for the data. Also be aware, that once you created another chart you won't be able to change the data of your previous charts."
})
#MAP view
output$map <- renderLeaflet({
print("MAP wird aufgerufen")
data <- as.numeric(coconut.df[[input$map_data]])
max_data<<- max(data)
c<-1
for(c in 1:length(data)){
data[c]<-(data[c]/max_data)*10
}
colorData <-
cut(
data,
c(0, 2, 5, 7, 10),
include.lowest = T,
lables = c('<2', '<5', '<7', '<10')
)
colorGrad <- colorFactor('RdYlGn', colorData)
#MAP
observeEvent(input$check_map, {
#Setting names
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
m <<- leaflet()
x=1
m <<- addTiles(m)
m<<-addCircleMarkers(m,lng=as.numeric(coconut.df$gps.longitude), lat=as.numeric(coconut.df$gps.latitude), radius = data, color = colorGrad(colorData)) #addPolylines does not work
m<<-addLegend(m, 'bottomright', pal=colorGrad, values=colorData, title=' ',opacity=1)
m
#Inserting box and plot
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
ui= box( width = 12,
title="Map",
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
selectInput(xplotname, "data", choices=colnames(coconut.df)),
leafletOutput(plotname, height = 250))
)
local({
output[[plotname]] <- renderLeaflet({
#handling data
data <- as.numeric(coconut.df[[input[[xplotname]]]])
#getting max for normation
max_data<<- max(data)
c<-1
#norming data
for(c in 1:length(data)){
data[c]<-(data[c]/max_data)*10
}
#encoding data
colorData <-
cut(
data,
c(0, 2, 5, 7, 10),
include.lowest = T,
lables = c('<2', '<5', '<7', '<10')
)
#color encoding data
colorGrad <- colorFactor('RdYlGn', colorData)
#new map
m <<- leaflet()
x=1
m <<- addTiles(m)
m<<-addCircleMarkers(m,lng=as.numeric(coconut.df$gps.longitude), lat=as.numeric(coconut.df$gps.latitude), radius = data, color = colorGrad(colorData)) #addPolylines does not work
m<<-addLegend(m, 'bottomright', pal=colorGrad, values=colorData, title=' ',opacity=1)
m
})
}) #Local end
})
#MAP text
output$map_explain <- renderText({
paste("Select data then go to add map. The map will show the way the participant went, also the data you selected is going to be normalized (highest value=10).")
})
"Here you can add a map. After clicking on the add button, a box with dropdownfield and a map will apear. Please set your wanted data. The map will show the way the participant went, also the data you selected is going to be normalized (highest value=10).Also be aware, that once you created another chart you won't be able to change the data of your previous charts."
})
#TODO: TOOLTIP
data_tooltip <- function(x){
......@@ -534,23 +602,7 @@ server <- function(input, output, session) {
}
#TODO: DownloadButton
plotinput <- function() {
#df<-data.frame(q=c(1,3,5,7,9),w=c(2,4,6,8,10),z=c(1,2,3,4,5))
list(p1 = map_plot,
p2 = line_plot,
p3 = scat_plot)
}
output$down.pdf <- downloadHandler(
##FIRST TRY
# print("download wird aufgerufen"),
# filename = function() { paste('plot', '.png', sep='') },
# content = function() {
# ggsave(plot=map_plot, file=input$nut$datapath)
#}
#SECOND TRY
#print("breakoint"),
filename = "download.pdf",
content = function(file) {
CairoPDF(file = file, width=12, height=8)
......@@ -558,34 +610,15 @@ server <- function(input, output, session) {
#m
#leafletOutput("map", height = 250)
output$box
# data<- structure(list(V1=as.numeric(coconut.df[[input$scat_x]]),
# V2=as.numeric(coconut.df[[input$scat_y]])),
# .Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
# plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )
data<- structure(list(V1=as.numeric(coconut.df[[input$scat_x]]),
V2=as.numeric(coconut.df[[input$scat_y]])),
.Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )
dev.off()
})
##THIRD TRY
# observeEvent(input$down.pdf, {
#
# pdf("www/myreport.pdf")
# plotinput()
# dev.off()
# tags$iframe(style="height:600px; width:100%", src="myreport.pdf")
#
# })
################## SOME STUFF ################
##DOWNLOADBUTTON
......