forked from caoalbert/TurbidityApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
59 lines (45 loc) · 1.78 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
# Import the packages
library(tidyverse)
library(googlesheets4)
library(shiny)
# Access Google token
options(
gargle_oauth_cache = ".secrets",
gargle_oauth_email = TRUE
)
# Name Plotting Variables
vars<- c("hydrolab_turbidity_ntu", "sentinel_acolite_turbidity_mean_fnu","landsat_acolite_turbidity_mean_fnu","tss")
ui<- fluidPage(
titlePanel("Turbidity"),
sidebarPanel(selectInput("xcol", "X Variable", vars),
selectInput("ycol", "Y Variable", vars),
actionButton("refresh", "refresh data")),
mainPanel(plotOutput("turbidityPlot"))
)
server<- function(input, output){
# Use refresh button to prepare data
dfCleaned<- eventReactive(input$refresh,{
hydro<- read_sheet("https://docs.google.com/spreadsheets/d/18TUgYYC6s6ZbgMIdV4XYZ72J_nrS0BfzQUxzfqFy2YY/edit#gid=0")
tss<- read_sheet("https://docs.google.com/spreadsheets/d/1-FOOyM14op9ojekoXiJ7Lx3qxvw4_lSBugtlzLVjdjU/edit#gid=0")
hydro<- hydro %>%
mutate(hydrolab_turbidity_ntu = as.numeric(unlist(hydrolab_turbidity_ntu)),
sentinel_acolite_turbidity_mean_fnu = as.numeric(unlist(sentinel_acolite_turbidity_mean_fnu)),
landsat_acolite_turbidity_mean_fnu = as.numeric(unlist(landsat_acolite_turbidity_mean_fnu)))
tss<- tss %>%
group_by(date_sample, sites)%>%
summarise(tss = mean(tss_g_l, na.rm = T))
hydro %>%
select(date_sample,
sites,
hydrolab_turbidity_ntu,
sentinel_acolite_turbidity_mean_fnu,
landsat_acolite_turbidity_mean_fnu ) %>%
left_join(tss, c("date_sample", "sites"))
})
# Create the plot
output$turbidityPlot<- renderPlot({
ggplot(dfCleaned(), aes_string(x = input$xcol, y = input$ycol))+
geom_point(aes(color = sites))
})
}
shinyApp(ui, server)