-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.R
78 lines (68 loc) · 2.41 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
library(shiny)
library(here)
source(here("soil_temp_data.R"))
ui <- fluidPage(
titlePanel("Optimal soil temperatures for vegetable seed germination"),
tabsetPanel(
tabPanel(
title = "Search by temperature",
sidebarPanel(
textInput("soiltemp", "Enter soil temperature in degrees F")
),
mainPanel(
h3("This is a good time to plant:"),
tableOutput("soil_input_table")
)
),
tabPanel(
title = "Search by crop",
sidebarPanel(
checkboxGroupInput("veg", label = "Select crop(s)", choices = soil_temp_data$crop)
),
mainPanel(
h3("Optimal soil temperatures for planting (degrees F):"),
tableOutput("crop_input_table")
)
),
tabPanel(
title = "Reference",
h4("Data were obtained from"),
tags$a(href = "https://extension.oregonstate.edu/sites/default/files/documents/12281/soiltemps.pdf",
"https://extension.oregonstate.edu/sites/default/files/documents/12281/soiltemps.pdf"),
br(),
br(),
h4("This app was created using"),
tags$a(href = "https://shiny.rstudio.com/", "Shiny"),
br(),
tags$a(href = "https://www.tidyverse.org/", "tidyverse"),
br(),
tags$a(href = "https://github.com/ropensci/tabulizer", "tabulizer")
)
)
)
server <- function(input, output) {
# search by temperature
output$soil_input_table <- renderTable({
req(input$soiltemp)
# get germination times using reference temp closest to input temp
# (ref temps are 9 degrees apart, so use ref temp +/- 4 from input temp)
nearest_ref_temp <- germination %>%
filter(((germination$ref_temp - 4) <= input$soiltemp) &
((germination$ref_temp + 4) >= input$soiltemp))
soil_temp_data %>%
filter(opt_min <= input$soiltemp & opt_max >= input$soiltemp) %>%
select(crop, opt_temp, opt_range) %>%
rename(Crop = crop, "Optimal temp (F)" = opt_temp, "Optimal temp range (F)" = opt_range) %>%
left_join(nearest_ref_temp, by = "Crop") %>%
select(-ref_temp) %>%
rename("Approx. germination time (days)" = germ_time)
})
# search by crop
output$crop_input_table <- renderTable({
soil_temp_data %>%
filter(crop %in% input$veg) %>%
select(-opt_range) %>%
rename(Crop = crop, "Min. temp" = opt_min, "Max. temp" = opt_max, "Optimal temp" = opt_temp)
})
}
shinyApp(ui = ui, server = server)