-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
153 lines (127 loc) · 5.36 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
SFB_DATA <- read.csv("SFB_DATA.csv")
head(SFB_DATA)
library(DT)
library(shiny)
library(shinydashboard)
library(leaflet)
library(sp)
library(dplyr)
ui <- dashboardPage(
dashboardHeader(title = 'San Francisco Bay Water Quality Survey Dashboard',
titleWidth = 500),
dashboardSidebar(
width = 300,
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Charts", tabName = "charts", icon = icon("th")),
menuItem("Create Alert", tabName = "alert", icon = icon("cog", lib = "glyphicon"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
fluidRow(
box(leafletOutput("mymap1",width = "100%",height = "500")),
box(plotOutput("plot")),
box(
title = "Please select Water Depth (m):",
sliderInput("sliderW", "Year:", 0, 15, 8.5)),
box(
title = "Station Information",
DTOutput("stationTable1"))
)
),
tabItem(tabName = "charts",
h2("Select chart type"),
fluidRow(
box(
title = "Please select Year",
sliderInput("slider", "Year:", 1994, 2014, 1999, round = TRUE, sep = "")),
box(
title = "Please select Month",
sliderInput("slider", "Month:", 1, 12, 6, round = TRUE, sep = "")),
box(
title = "Water temperature (Celsius)",
plotOutput("hist", click = "plot_click"),
verbatimTextOutput("infoHist")
),
box(title = "Salinity",
plotOutput("scatter", click = "plot_click"),
verbatimTextOutput("infoScatter")
)
)
),
tabItem(tabName = "alert",
h3("Create your customized alert")
)
)
)
)
server <- function(input, output) {
stationInfoRel <- stationInfo
stationInfoRel$Latitude.Dec <- NULL
stationInfoRel$Longitude.Dec <- NULL
id = stationInfo$General.Location
data_of_click <- reactiveValues(clickedMarker=NULL)
output$stationTable1 <- renderDT(stationInfoRel)
output$infoScatter <- renderText({
paste0("Temperature =",input$plot_click$x, "\nSalinity =", input$plot_click$y)
})
SFB_DATA2014 <- filter(SFB_DATA, Year == 2014)
output$scatter <- renderPlot({
title <- "scatter"
plot(SFB_DATA2014$Temperature, SFB_DATA2014$Salinity,
pch = 16, col = "blue",
xlab = "Temperature in Celsius",
ylab = "Salinity")
})
'output$infoHist <- renderText({
paste0("Temperature = ", input$plot_click$x, "\nFrequency = ", input$plot_click$y)
})'
output$hist <- renderPlot({
title <- "histogram"
hist(SFB_DATA$Temperature,
main= paste(""),
xlab = "Temperature in Celsius",
ylab = "Cumulated Frequency")
})
output$mymap1 <- renderLeaflet({
stationInfo <- read.csv("stationInfo.csv")
# making sure the Longitude.Dec column is number column (not text, char)
stationInfo$Longitude.Dec <- as.numeric(stationInfo$Longitude.Dec)
stationInfo$Latitude.Dec <- as.numeric(stationInfo$Latitude.Dec)
# create new spatial points data frame (where to find geocoordinates Lat, Long)
stationInfo.SP <- SpatialPointsDataFrame(stationInfo[,c(3,4)], stationInfo[,-c(3,4)])
# center the map on 37.898193, -122.070647
myMap <- leaflet() %>%
addProviderTiles("Esri.WorldGrayCanvas") %>%
addCircleMarkers(data = stationInfo,
lng = ~Longitude.Dec,
lat = ~Latitude.Dec,
radius = 4,
popup = ~paste("Station ID:", Station.Number, "<br>", #inside paste you can use HTML
"Location/Name:", General.Location, "<br>",
"Water Depth (m):", Depth.MLW..meters., "<br>",
"Standard Station:", Standard.Station
)
)
})
observeEvent(input$map_marker_click,{
data_of_click$clickedMarker <- input$map_marker_click
})
output$plot <- renderPlot({
my_place=data_of_click$clickedMarker$id[]
if(is.null(my_place)){my_place="Rio Vista"}
if(my_place=="Rio Vista"){
#plot(rnorm(1000), col=rgb(0.9,0.4,0.1,0.3), cex=3, pch=20)
plot(SFB_DATA2013$Depth, SFB_DATA2013$Temperature,
main = paste("Water temperature with varying Depth"),
pch = 16, col = "orange",
xlab = "Depth in metres",
ylab = "Temperature in Celsius")
}else{
barplot(rnorm(10), col=rgb(0.1,0.4,0.9,0.3))
}
})
}
shinyApp(ui = ui, server = server)