Skip to content

Commit 490c365

Browse files
committed
Update to new renamed field names
1 parent 679d9da commit 490c365

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

App/Zooniverse/functions.R

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library(gridExtra)
77
library(stringr)
88
library(htmltools)
99
library(tidyr)
10+
library(leaflet.providers)
1011

1112
#Site map
1213
create_map<-function(colonies){
@@ -59,8 +60,22 @@ filter_annotations<-function(raw_data){
5960
return(selected_boxes)
6061
}
6162

62-
totals_plot<-function(selected_boxes){
63-
ggplot(selected_boxes) + geom_bar(aes(x=species)) + coord_flip() + ggtitle("Project Total") + labs(x="Label") + theme(text = element_text(size=20))
63+
species_colors <- colorFactor(palette = c("yellow", "blue",
64+
"#ff007f", "brown",
65+
"purple", "white"),
66+
domain = c("Great Egret", "Great Blue Heron",
67+
"Roseate Spoonbill", "Wood Stork",
68+
"Snowy Egret", "White Ibis"),
69+
ordered=TRUE)
70+
71+
totals_plot <- function(selected_boxes) {
72+
ggplot(selected_boxes, aes(x = species, fill = species_colors(species))) +
73+
geom_bar() + coord_flip() + ggtitle("Project Total") + labs(x = "Label") +
74+
scale_fill_identity(guide = "none") +
75+
theme(
76+
text = element_text(size = 20),
77+
panel.background = element_rect(fill = "#add8e6")
78+
)
6479
}
6580

6681
site_totals<-function(selected_boxes){
@@ -77,21 +92,20 @@ site_phenology<-function(selected_boxes){
7792
theme(text = element_text(size=20))
7893
}
7994

80-
plot_annotations<-function(selected_boxes, MAPBOX_ACCESS_TOKEN){
81-
pal <- colorFactor(
82-
palette = 'Dark2',
83-
domain = selected_boxes$species
84-
)
85-
86-
selected_centroids<-st_transform(selected_boxes,4326)
95+
plot_annotations<-function(selected_boxes, MAPBOX_ACCESS_TOKEN) {
96+
pal <- colorFactor(palette = "Dark2", domain = selected_boxes$species)
97+
98+
# Convert polygons to centroids
99+
selected_centroids <- st_centroid(selected_boxes)
100+
selected_centroids <- st_transform(selected_centroids, 4326)
87101

88-
#Create mapbox tileset
89-
mapbox_tileset<-unique(selected_centroids$tileset_id)
90-
mapbox_tileset<-paste("bweinstein.",mapbox_tileset,sep="")
102+
# Create mapbox tileset
103+
mapbox_tileset <- unique(selected_centroids$tileset_id)
104+
mapbox_tileset <- paste("bweinstein.", mapbox_tileset, sep = "")
91105

92-
m<-leaflet(data=selected_centroids) %>%
93-
addProviderTiles("MapBox", options = providerTileOptions(id = mapbox_tileset, minZoom = 8, maxNativeZoom=24, maxZoom = 24, accessToken = MAPBOX_ACCESS_TOKEN)) %>%
94-
addCircles(stroke = T,color=~pal(species),fillOpacity = 0.1,radius = 0.25,popup = ~htmlEscape(label))
106+
m <- leaflet(data = selected_centroids) %>%
107+
addProviderTiles("MapBox", options = providerTileOptions(id = mapbox_tileset, minZoom = 8, maxNativeZoom = 24, maxZoom = 24, accessToken = MAPBOX_ACCESS_TOKEN)) %>%
108+
addCircles(stroke = T, color=~pal(species),fillOpacity = 0.1, radius = 0.25, popup = ~htmlEscape(label))
95109
return(m)
96110
}
97111

@@ -152,21 +166,13 @@ nest_history<-function(dat){
152166
theme(axis.text.x = element_text(angle = -90),text = element_text(size=20))
153167
}
154168

155-
species_colors <- colorFactor(palette = c("yellow", "blue",
156-
"#ff007f", "brown",
157-
"purple", "white"),
158-
domain = c("Great Egret", "Great Blue Heron",
159-
"Roseate Spoonbill", "Wood Stork",
160-
"Snowy Egret", "White Ibis"),
161-
ordered=TRUE)
162-
163169
plot_nests<-function(df, bird_df, MAPBOX_ACCESS_TOKEN){
164170
mapbox_tileset<-unique(bird_df$tileset_id)[1]
165171
mapbox_tileset<-paste("bweinstein.",mapbox_tileset,sep="")
166172

167173
m<-leaflet(data=df) %>%
168174
addProviderTiles("MapBox", layerId = "mapbox_id",options = providerTileOptions(id = mapbox_tileset, minZoom = 8, maxNativeZoom=24, maxZoom = 24, accessToken = MAPBOX_ACCESS_TOKEN)) %>%
169-
addCircles(stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs_to,2),nest_id,sep=":"))) %>%
175+
addCircles(stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs,2),nest_id,sep=":"))) %>%
170176
addCircles(data = bird_df, stroke = T, fillOpacity = 0, radius = 0.2, color = ~species_colors(label),
171177
popup = ~htmlEscape(paste(round(score,2), bird_id, sep=":")))
172178
return(m)
@@ -193,7 +199,7 @@ update_nests<-function(mapbox_tileset, df, bird_df, show_nests, show_birds,
193199
}
194200
if (show_nests) {
195201
map <- map %>%
196-
addCircles(data=df,stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs_to,2),nest_id,sep=", ")))
202+
addCircles(data=df,stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs,2),nest_id,sep=", ")))
197203
}
198204
if (show_birds) {
199205
map <- map %>%
@@ -215,10 +221,9 @@ zooniverse_complete<-function(){
215221
subject_data<-read.csv("data/everglades-watch-subjects.csv")
216222
raw_annotations<-read.csv("data/parsed_annotations.csv")
217223
subject_data$Site<-sapply(subject_data$metadata, function(x) str_match(gsub('\"', "", x, fixed = TRUE),"site:(\\w+)")[,2])
218-
219224
#images per site
220225
completed<-subject_data %>% group_by(Site) %>% mutate(annotated=subject_id %in% raw_annotations$subject_ids) %>% select(Site,subject_id, annotated) %>% group_by(Site, annotated) %>% summarize(n=n_distinct(subject_id)) %>%
221226
tidyr::spread(annotated,n, fill=0) %>% mutate(Percent_Complete=`TRUE`/(`TRUE`+`FALSE`)*100)
222227
p<-ggplot(completed,aes(x=Site,y=Percent_Complete)) + coord_flip() + geom_bar(stat="identity") + labs(y="Annotated (%)",x="Subject Set")
223228
return(p)
224-
}
229+
}

App/Zooniverse/landing_page.R

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
landing_page<-function(selected_boxes){
1+
landing_page <- function(selected_boxes) {
22

3-
site_list<-c("All", unique(selected_boxes$site))
4-
select_image_list<-unique(selected_boxes$tileset_id)
3+
site_list <- c("All", unique(selected_boxes$site))
4+
select_image_list <- unique(selected_boxes$tileset_id)
55

66
renderUI({
77
fluidPage(
8-
sidebarPanel(leafletOutput("map",height=900)),
9-
mainPanel(h2("Zooniverse Summary"),
10-
p(textOutput("summary")),
11-
plotOutput("zooniverse_anotation"),
12-
13-
plotOutput("totals_plot",height=400),
14-
h2("Select Sites"),
15-
selectizeInput("landing_site", "Site", site_list, selected = "All", multiple = TRUE,options = NULL),
16-
plotOutput("site_totals_plot",height=400),
17-
18-
h2("View Annotations"),
19-
selectizeInput("selected_image", "Site", select_image_list, selected = "JetportSouth_03_23_2020", multiple = FALSE,options = NULL),
20-
leafletOutput("colony_map",height=1000)
8+
sidebarPanel(leafletOutput("map", height = 900)),
9+
mainPanel(
10+
h2("Zooniverse Summary"),
11+
p(textOutput("summary")),
12+
plotOutput("zooniverse_anotation", height = 500),
13+
plotOutput("totals_plot", height = 300),
14+
15+
h2("Select Sites"),
16+
selectizeInput("landing_site", "Site", site_list, selected = "All", multiple = TRUE, options = NULL),
17+
plotOutput("site_totals_plot", height = 400),
18+
19+
h2("View Annotations"),
20+
selectizeInput("selected_image", "Site", select_image_list, selected = "JetportSouth_03_23_2020", multiple = FALSE, options = NULL),
21+
leafletOutput("colony_map", height = 800),
22+
tags$br(), tags$br(), tags$br(),
23+
div(
24+
class = "footer",
25+
"Copyright (c) 2020-present Weecology, University of Florida, and the contributors"
26+
),
27+
tags$br(),
2128
)
22-
)})
23-
}
29+
)
30+
})
31+
}

App/Zooniverse/server.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ shinyServer(function(input, output, session) {
8888
#filter based on selection
8989
to_plot <- selected_boxes %>% filter(tileset_id==input$selected_image)
9090
return(to_plot)
91+
9192
})
9293

9394
observe({
94-
output$colony_map<-renderLeaflet(plot_annotations(selected_boxes =colony_filter(),MAPBOX_ACCESS_TOKEN))
95+
output$colony_map<-renderLeaflet(plot_annotations(selected_boxes=colony_filter(),MAPBOX_ACCESS_TOKEN))
9596
})
9697

98+
9799
##Prediction page##
98100
prediction_filter<-reactive({
99101
#filter based on selection

0 commit comments

Comments
 (0)