-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
92 lines (76 loc) · 2.96 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
library(shiny) # web app framework
library(shinyjs) # improve user experience with JavaScript
library(shinydashboard) # dashboard layout for shiny
library(shinythemes) # themes for shiny
library(shinycssloaders)
library(sqldf) # run SQL query on a Data frame
library(summarytools) # data summary
library(scales) # plot formatting scale
library(tidyverse) # data manipulation
library(ggplot2)
library(dplyr)
library(magrittr)
library(ggrepel)
library(plotly)
library(RColorBrewer)
library(rgdal) # Read shapefile
library(leaflet)
library(htmltools)
# ====================================
# === Global Variables ===
# ====================================
cur_timezone <- Sys.timezone(location = TRUE)
shape <- readOGR("building.shp")
studentdata <- read.csv("focusGroupStudent/df_allStudent.csv", header = TRUE)
studentdata$fp <- NULL
studentdata$Datetime = as.POSIXct(studentdata$Time, format = "%m/%d/%Y %H:%M:%S")
# create unique building data.frame
bb <- unique(studentdata$building)
all_building <- data.frame(bb)
all_building <- all_building[order(all_building$bb),]
all_building <- data.frame(all_building)
names(all_building) <- c('filtered_data$building')
# ====================================
# === UI ===
# ====================================
ui <- dashboardPage(
dashboardHeader(
title = "CrowdViewer"
),
dashboardSidebar(collapsed = TRUE,
# set welcome HTML
div(htmlOutput("welcome"), style = "padding: 20px"),
sidebarMenu(id="sidebar001",
menuItem("Data Dashboard (6 months)", tabName = "tab_3", icon = icon("dashboard")),
menuItem("Data Dashboard (1 day)", tabName = "tab_4", icon = icon('calendar-day'))
)
),
dashboardBody(
# define tabItems with separated UI R script
tabItems(
tabItem(tabName = "tab_3", source(file.path("ui", "tab_6months.R"), local = TRUE)$value),
tabItem(tabName = "tab_4", source(file.path("ui", "tab_1day.R"), local = TRUE)$value)
),
# enable shinyjs
shinyjs::useShinyjs(),
# tag header, script, css, etc.
tags$head(tags$style(".table{margin: 0 auto;}"),
tags$script(src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.16/iframeResizer.contentWindow.min.js",type="text/javascript"),
tags$style(HTML("
.shiny-output-error-validation {
color: red;
}
"))
)
)
)
# ====================================
# === Server ===
# ====================================
server <- function(input, output, session) {
# loading server function for each tab item
source(file.path("server", "tab_6months.R"), local = TRUE)$value
source(file.path("server", "tab_1day.R"), local = TRUE)$value
}
# define shinyApp
shinyApp(ui = ui, server = server)