-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
82 lines (69 loc) · 2.79 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
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(ggplot2)
data_url <- "https://arcticdata.io/metacat/d1/mn/v2/object/urn%3Auuid%3A35ad7624-b159-4e29-a700-0c0770419941"
bg_chem <- read.csv(url(data_url, method="libcurl"), stringsAsFactors = FALSE) %>%
select(-Date, -Time, -Station)
cols<-names(bg_chem)
# Sometimes you need to wrap the web address in url() on some platforms
#bg_chem <- read.csv(url(data_url, method = "libcurl"), stringsAsFactors = FALSE), different computers handle downloading data from the web in different ways, in windows read.csv does not know how to deal with https servers, so url function, tells windows to use a different method to deal with https urls, giving windows more instruction
names(bg_chem)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Water Biogeochemistry"),
# Sidebar with a slider input for number of bins
verticalLayout(
sidebarLayout(
sidebarPanel(
sliderInput("depth",
"Depth:",
min = 0,
max = 500,
value = c(0,100))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
),
sidebarLayout(
sidebarPanel(
selectInput("x_variable","X Variable", cols, selected = "CTD_Salinity"),
selectInput("y_variable","Y Variable", cols, selected = "d18O"),
selectInput("color_variable","Color", cols, selected = "P"),
),
# Show a plot of a selectd set of variables
mainPanel(
plotOutput("varPlot")
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
ggplot(bg_chem, mapping = aes(x=CTD_Depth, y = CTD_Salinity))+
geom_point(color='red', size = 4) +
xlim(input$depth[1], input$depth[2])+
theme_light()
})
output$varPlot <- renderPlot({
ggplot(bg_chem, mapping = aes_string(x=input$x_variable, y = input$y_variable, color = input$color_variable))+
geom_point(size = 4) +
scale_color_gradient2(low="midnightblue",
mid="white",
high="firebrick",
midpoint=mean(bg_chem[,input$color_variable]))+
theme_light()
})
}
# Run the application
shinyApp(ui = ui, server = server)