Commit 8916e138 authored by Stephanie Wegscheidl's avatar Stephanie Wegscheidl

structure code, tries to make multiple charts work and updating help page

parent 0145b675
library(shiny)
library(jsonlite)
library(DT)
library(webshot)
library(knitr)
library(leaflet)
library(mapview)
library(ggplot2)
library(timevis)
#library(plotly)
library(jsonlite) # to handle the json file data correctly
library(DT) # to render the data-tables correctely
#library(webshot) # corrently not in use should work for the downloadbutton
#library(knitr) # supposed to do Dynamic Report Generation in R
library(leaflet) # to render the map --> instead of google
#library(mapview) # not in use but could be used for map instead of leaflet
#library(ggplot2) # not in use but for rendering plots
library(timevis) # for rendering the fancy timeline
#library(plotly) # not in use but for rendering plots
library(Cairo) #creating the pdf for download
library(grDevices) # also necessary for the download
library(anytime) # for correctly parsing unixtimestamps into readable date and time formats
library(shinydashboard) # creating the structure / dashboard structure-items
server <- function(input, output, session) {
set.seed(122)
......@@ -190,9 +192,7 @@ server <- function(input, output, session) {
#Title Input
output$title <- renderText({ input$title })
#barchart
#selectInput("time_data", "data", choices=colnames(coconut.df))
#BARCHART selectinputs
output$input_hist_x <- renderUI({
if (is.null(input$nut))
return(NULL)
......@@ -206,7 +206,7 @@ server <- function(input, output, session) {
})
#Timeline
#TIMELINE selectinput--> do not need it
# output$input_time_data <- renderUI({
# if (is.null(input$nut))
......@@ -220,52 +220,42 @@ server <- function(input, output, session) {
# 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)
# })
#Map
output$input_map <- renderUI({
if (is.null(input$nut))
return(NULL)
selectInput("map_data", "data", choices=colnames(coconut.df))
})
#linechart
#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
#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
#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)
......@@ -273,6 +263,12 @@ server <- function(input, output, session) {
})
#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
......@@ -281,16 +277,24 @@ server <- function(input, output, session) {
updateTabItems(session, "tabs",selected = "dashboard")
})
plotCounter <<- 0
#ADD BARCHART BUTTON
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, {
plotname<<-paste("plot", plotCounter, sep="")
plotCounter<<-plotCounter+1
print(plotCounter)
plotname <<- paste("plot", plotCounter, sep="")
print(plotname)
xplotname<<- paste("x",plotname,sep="")
yplotname<<-paste("y",plotname, sep="")
print(plotCounter)
print(plotname)
insertUI(
selector= "#viewpanel", #wo will ichs hinhaben
......@@ -299,35 +303,33 @@ server <- function(input, output, session) {
status= "warning",
solidHeader = TRUE,
collapsible = TRUE,
# selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
# selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
print(plotname),
plotOutput(plotname, height = 250))
)
})
#DASHBOARD
#BAR VIEW
#BARCHART view
# #local({
#
#
# #
# # output[[plotname]] <- renderPlot({
# # print(plotname)
# #
# # 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,6L), class = "data.frame")
# # #Neues Plot
# # barplot(data$V1,data$V2,
# # ylab= input$yplotname,
# # xlab=input$xplotname)
# #
# # })
# #})
local({
output[[plotname]] <- renderPlot({
print("hello itse mi")
print(input$xplotname)
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,6L), class = "data.frame")
#Neues Plot
barplot(data$V1,data$V2,
ylab= input$yplotname,
xlab=input$xplotname)
})
})
## ALTES PLOT
#a=1
......@@ -345,10 +347,14 @@ server <- function(input, output, session) {
#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
#TIMELINE insert box
output$time_box <- renderUI({
if(input$check_time)
box( width = 12,
......@@ -360,7 +366,7 @@ server <- function(input, output, session) {
)
})
#TODO: Timelineview
#TIMELINE view
output$time <- renderTimevis({
print("TIME wird aufgerufen")
......@@ -382,13 +388,13 @@ server <- function(input, output, session) {
})
#TIMELINE text
output$texttimeline <- renderText({
"Check Timeline for getting a Timeline about CoCoQuest Tasks and Questions."
"Add Timeline for getting a Timeline about CoCoQuest Tasks and Questions.To see how long a the participant took for a certain task."
})
#linechart
#LINECHART insert box
output$line_box <- renderUI({
if(input$check_line)
box( width = 12,
......@@ -401,7 +407,7 @@ server <- function(input, output, session) {
line_plot<<-plotOutput("line", height = 250))
})
#TODO: linechart View
#LINECHART view
output$line <- renderPlot({
print("LINE wird aufgerufen")
data<- structure(list(V1=as.numeric(coconut.df[[input$line_x]]),
......@@ -411,7 +417,13 @@ server <- function(input, output, session) {
})
# Scatterplot
#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."
})
#SCATTERPLOT insert box
output$scat_box <- renderUI({
if(input$check_scat)
box( width = 12,
......@@ -423,7 +435,7 @@ server <- function(input, output, session) {
scat_plot<<- plotOutput("scat", height = 250))
})
#TODO: Scatterplot View
#SCATTERPLOT view
output$scat <- renderPlot({
data<- structure(list(V1=as.numeric(coconut.df[[input$scat_x]]),
V2=as.numeric(coconut.df[[input$scat_y]])),
......@@ -433,7 +445,12 @@ server <- function(input, output, session) {
plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )
})
# Boxplot
#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."
})
#BOXPLOT insert box
output$box_box <- renderUI({
if(input$check_box)
box( width = 12,
......@@ -445,7 +462,8 @@ server <- function(input, output, session) {
box_plot<<- plotOutput("box", height = 250))
})
#TODO: Boxplot View
#BOXPLOT view
#TODO:scaling
output$box <- renderPlot({
print("BOX wird aufgerufen")
data<- structure(list(V1=as.numeric(coconut.df[[input$box_x]])),
......@@ -454,7 +472,12 @@ server <- function(input, output, session) {
boxplot(data$V1, type="box", xlab=input$box_x )
})
#MAP
#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,
......@@ -466,12 +489,11 @@ server <- function(input, output, session) {
map_plot<<-leafletOutput("map", height = 250))
})
# MAP VIEW
#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
......@@ -484,34 +506,30 @@ server <- function(input, output, session) {
include.lowest = T,
lables = c('<2', '<5', '<7', '<10')
)
print("colorData")
print(colorData)
colorGrad <- colorFactor('RdYlGn', colorData)
print("colorGrad")
print(colorGrad(colorData))
m <- leaflet()
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 <<- 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
})
#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).")
})
# TOOLTIP
#TODO: TOOLTIP
data_tooltip <- function(x){
if(is.null(x)) return(NULL)
if(is.null(x$ID)) return(NULL)
paste0(coconut.df[[input$line_x]])
}
#DownloadButton
#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,
......@@ -528,11 +546,14 @@ server <- function(input, output, session) {
#}
#SECOND TRY
filename = function(){paste("Graphs","pdf", sep=".")},
print("breakoint"),
filename = function(){paste("Graphs",'.pdf', sep='')},
content = function(file) {
cairo_pdf(file = file, width=12, height=8)
cairo_pdf(filename = file, width=12, height=8)
#boxplot(data$V1, type="box", xlab=input$box_x)
map_plot
#m
#leafletOutput("map", height = 250)
plot()
dev.off()
})
......@@ -549,37 +570,47 @@ server <- function(input, output, session) {
#TODO: MAKE IT WORK!
################## SOME STUFF ################
##DOWNLOADBUTTON
#observeEvent(input$screenshot,{
#if(input$check_line|input$check_time|input$check_map|input$check_hist)
#disable("screenshot")
#webshot::install_phantomjs()
# cdat <<- session$clientData
# url <- paste0(cdat$url_hostname,":", cdat$url_port,"/")
# print(url)
#URL <- "http://rstudio.github.io/leaflet/"
#appshot("cocoVisR/", file = "dashboard.png", port = getOption("shiny.port"), envvars = NULL)
#webshot(url,delay = 5.0)
#knit("dashboard.png")
#port <- cdat$url_port
#mapshot(m, file="~/Rplot.png")
#webshot(url, "dashboard.png", delay = 20.0) # does NOT WORK
#appdir <- system.file("examples", "01_hello", package="shiny")
#print("appdir")
#print(appdir)
#appshot(appdir, "01_hello.png")
#leaflet.print(m)
#if(input$check_line|input$check_time|input$check_map|input$check_hist)
#disable("screenshot")
#webshot::install_phantomjs()
# cdat <<- session$clientData
# url <- paste0(cdat$url_hostname,":", cdat$url_port,"/")
# print(url)
#URL <- "http://rstudio.github.io/leaflet/"
#appshot("cocoVisR/", file = "dashboard.png", port = getOption("shiny.port"), envvars = NULL)
#webshot(url,delay = 5.0)
#knit("dashboard.png")
#port <- cdat$url_port
#mapshot(m, file="~/Rplot.png")
#webshot(url, "dashboard.png", delay = 20.0) # does NOT WORK
#appdir <- system.file("examples", "01_hello", package="shiny")
#print("appdir")
#print(appdir)
#appshot(appdir, "01_hello.png")
#leaflet.print(m)
#})
# url <- paste0(cdat$url_protocol,"//",cdat$url_hostname,":", cdat$url_port, cdat$url_pathname,cdat$url_search)
#output$downButton <- downloadHandler(
......@@ -594,12 +625,7 @@ server <- function(input, output, session) {
#SOME STUFF
##BARCHART
#histdata <- rnorm(500)
#output$plot1 <- renderPlot({
......
......@@ -2,7 +2,7 @@
library(shiny)
library(shinydashboard)
#library(jsonlite)
library(anytime)
library(anytime) # convert unixtimestamps to readable date and time
#library(leaflet)
ui <- dashboardPage(
......@@ -75,8 +75,9 @@ ui <- dashboardPage(
tabsetPanel(
tabPanel("Barchart",
#Barchart
uiOutput("input_hist_x"),
uiOutput("input_hist_y"),
textOutput("bar_explain"),
#uiOutput("input_hist_x"),
# uiOutput("input_hist_y"),
actionButton("check_hist", "add Barchart")
),
......@@ -91,6 +92,7 @@ ui <- dashboardPage(
#Linechart
tabPanel("Linechart",
textOutput("line_explain"),
uiOutput("input_line_x"),
uiOutput("input_line_y"),
actionButton("check_line", "add Linechart")
......@@ -100,6 +102,7 @@ ui <- dashboardPage(
tabPanel("Scatterplot",
# selectInput("scat_x", "x-axis", choices=colnames(coconut.df)),
# selectInput("scat_y", "y-axis", choices=colnames(coconut.df)),
textOutput("scat_explain"),
uiOutput("input_scat_x"),
uiOutput("input_scat_y"),
actionButton("check_scat", " add Scatterplot")
......@@ -108,6 +111,7 @@ ui <- dashboardPage(
#Boxplot
tabPanel("Boxplot",
# selectInput("box_x", "x-axis", choices=colnames(coconut.df)),
textOutput("box_explain"),
uiOutput("input_box_x"),
#uiOutput("input_box_y"),
actionButton("check_box", "add Boxplot")
......@@ -118,6 +122,7 @@ ui <- dashboardPage(
#MAP
tabPanel("Map",
# selectInput("map_data", "data", choices=colnames(coconut.df)),
textOutput("map_explain"),
uiOutput("input_map"),
actionButton("check_map", "add Map")
)
......@@ -177,21 +182,26 @@ ui <- dashboardPage(
# Help tab content
tabItem(tabName = "help",
h2("I am here to Help."),
"This tool was created to help visualize and analyse data which is recorded with the CoConUT and CoCoQuest Applications.",
h3("General Information"),
"This tool was created to help visualize and analyse data which is recorded with the CoConUT and CoCoQuest Applications. Please follow the next buttons, or the menu on the left side step by step. This will help you to work with this tool correctly.",
h3("Uploading Data"),
"Please make sure the files you want to upload are *.json files Otherwise the upload won't work.", br(),
"For uploading you have to click on the 'Browse'-Button and an explorer-window will open.", br(),
"Please navigate to the wanted file, select it and click on 'open'.
"Please make sure the files you want to upload are *.json files. Otherwise the upload won't work.", br(),
"For uploading you have to click on the 'Browse'- Button and an explorer-window will open.", br(),
"Please navigate to the wanted file, select it and click on 'open' or double click on it.
Then the name of the selected file and a loadingbar will apear. 'Upload complete' will show you that the upload worked and is finished.", br(),
"Please make sure, that you upload the right data into the right field. If not please upload the correct file in the right fields. ", br(),
"First field: CoConUT and second field: CoCoQuest. Otherwise the visualization won't work.",
h3("Data"),
"After correctly loading up the right json files, in this vies will apear a table that shows the data that were red from the jsons. Also the names of the loaded files will apear, here you can check again, if the uploaded files where the right ones.", br(),
h3("Controlls"),
"On this page you are able to select the visualizations you want to use and which data should be in them.", br(), "Also you can enter the title of your dashboard.",
"To show a visualization on the dashboard you have to enable the right checkbox. After that you need to select the x- and y-axis for this visualisation and then it will be added to the dashboard. ",
h3("Dashboard"),
"Here you can now find your selected visualizations. Also there is a download button which will create a screenshot which you can save on your device.", br()
"Do not skip this step. Otherwise the application will not load the needed data correctly. If you skiped this step, you might have to start the application new and do the upload again.",br(),
"After correctly loading up the right json files, there will apear a table that shows the data that were red from the uploaded jsons. The first table contains the CoConUT.json data and the second table contains the CoCoQuest.json data.",br(),
"Also the names of the loaded files will apear, here you can check again, if the uploaded files where the right ones. Please note, that there is a 'go to views'-button in the lower left corner, which will lead you to the next step.", br(),
h3("Views"),
"Here you can see which visualizations are possible within the Application. This tool is supposed to be supplemented by the user with functions they need.
On this page you are able to select the visualizations you want to use and which data should be in them.", br(), "Also you can enter the title of your dashboard.",
"You can also add the vizualisations to the dashboard, which is shown on the right side of this view.
First you need click on the tab of the view you want to add to the dashboard, then select the data you want the visualization to contain (x- and y-axis or data). ",br(),
"Then you will need to click on the button 'add *view*', right then the selected view should appear in the dashboard."
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment