forked from regan008/mgg-lc-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
82 lines (62 loc) · 2.78 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
library(leaflet)
library(RColorBrewer)
library(scales)
library(lattice)
library(dplyr)
library(ggplot2)
library(plotly)
library(maps)
library(DT)
function(input, output, session) {
# Reactive expression for filtered data
filteredData <- reactive({
req(mgg.gg.data) # Ensure mgg.gg.data is available
data <- mgg.gg.data
#data <- separate(data, geocode.value, into = c("city", "state", "country"), sep = ",")
if (input$noncontiguous == FALSE) {
data <- data %>% filter(!grepl("HI|AK|VI", geocode.value))
}
if (input$gg == FALSE) {
data <- data %>% filter(publication != "Gaia's Guide")
}
if (input$mgg == FALSE) {
data <- data %>% filter(publication != "Bob Damron's Address Book")
}
data
})
filteredTable <- reactive({
req(full.data)
tbldata <- full.data
tbldata <- tbldata %>% filter(input$cityvalue == geocode.value)
tbldata <- tbldata %>% select(-city, -state, -country, -notes, -lon, -lat, -geoAddress)
tbldata
})
#table
observe({
# Assuming 'publication' and 'geocode.value' are the columns you want to include in the tooltip
p <- ggplot() +
geom_polygon(data = map_data("state"), aes(x = long, y = lat, group = group), fill = "gray90", color = "white") +
geom_point(data = filteredData(), aes(x = lon, y = lat, size = relative.percentage, color = publication, text = paste("Publication:", publication, "<br>Count:", count, "<br>Geocode Value:", geocode.value)), alpha = 0.5) +
scale_color_manual(values = c("Gaia's Guide" = "#0F8554", "Bob Damron's Address Book" = "#6F4070")) + # Manually set colors
theme(axis.text.x = element_blank(), axis.text.y = element_blank(), # Remove axis labels
axis.ticks = element_blank(), # Remove axis ticks
panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + #Remove gridlines
labs(title = paste("Gaia's Guide & Damron's Guide: ", unique_years_string)) # Add the dynamically created title at the top of the map
# Directly render the updated plot to output$map
output$map <- renderPlotly({
ggplotly(p, tooltip = "text")
})
output$dtable <- renderDT({
filteredTable()
})
#map
output$map <- renderPlotly({
usa <- map_data("state")
p <- ggplot(data = filteredData(), aes(x = lon, y = lat)) +
geom_polygon(data = map_data("state"), aes(x = long, y = lat, group = group), fill = "gray90", color = "white") +
geom_point(aes(size = relative.percentage, color = publication, text = paste("Publication:", publication, "<br>Count:", count, "<br>Geocode Value:", geocode.value)), alpha = 0.5) +
scale_color_manual(values = c("#0F8554", "#6F4070")) +
theme(legend.position = "none")
})
})
}