-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
108 lines (80 loc) · 3.15 KB
/
server.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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(leaflet)
library(shinyBS)
library("bsplus")
library("lutz")
click <- NA
rxData <- NA
lat <- NA
long <- NA
source("functions.R")
shinyServer(function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
setView(-93.65, 39, zoom = 4) %>%
addProviderTiles(providers$Esri.NatGeoWorldMap)})
observeEvent(input$map_click,{
leafletProxy('map') %>% clearMarkers()
click <<- input$map_click
lat <<- click$lat
long <<- click$lng
if(is.null(click))
return()
leafletProxy('map')%>%addMarkers(lng = long, lat = lat)
})
observeEvent(input$button,{
if(is.null(click))
return()
withProgress(message = 'Downloading data...', value = 0, {
getData <- latlongReturnDF(lat = lat, long = long, unitConvert = TRUE)
incProgress(1/5,message = "Interpolating data...")
interpData <- interpolateTime(getData,type = "spline")
incProgress(2/5,message = "Calculating timezone...")
tz_fromInput <- tz_lookup_coords(lat, long, method = "accurate")
interpData$dt <- with_tz(interpData$dt, tzone = tz_fromInput)
print(input$fuelModel)
incProgress(3/5,message = "Calculating fire behavior...", detail = "(This may take a while.)")
interpData2 <- fxn_firebehavior(interpData, input$fuelModel,LH = input$liveHFM,LW = input$liveWFM)
incProgress(4/5,message = "Calculating prescription...")
rxData <<- prescription(df = interpData2,
tempHi = input$rxTempInput[2],
tempLo = input$rxTempInput[1],
windHi = input$rxWindInput[2],
windLo = input$rxWindInput[1],
rhHi = input$rxRHInput[2],
rhLo = input$rxRHInput[1],
ffmHi = input$rxFFMInput[2],
ffmLo = input$rxFFMInput[1],
flHi = input$rxFLInput[2],
flLo = input$rxFLInput[1])
incProgress(5/5,message = "Done!")
})
updateTabsetPanel(session, "nav",selected = "Output")
})
output$rxPlot <- renderPlot({
validate(
need(input$button, 'Please select a location and press the button!'))
outRxPlot <- rxPlot(df = rxData,
lat = lat,
long = long,
rhHi = input$rxRHInput[2],
rhLo = input$rxRHInput[1],
wsHi = input$rxWindInput[2],
wsLo = input$rxWindInput[1],
tempHi = input$rxTempInput[2],
tempLo = input$rxTempInput[1],
ffmHi = input$rxFFMInput[2],
ffmLo = input$rxFFMInput[1],
flHi = input$rxFLInput[2],
flLo = input$rxFLInput[1])
outRxPlot
})
})