Skip to content

Commit 46a82f0

Browse files
committed
Update to new renamed field names
1 parent 679d9da commit 46a82f0

File tree

3 files changed

+65
-46
lines changed

3 files changed

+65
-46
lines changed

App/Zooniverse/functions.R

Lines changed: 36 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,26 @@ 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+
# totals_plot<-function(selected_boxes){
64+
# ggplot(selected_boxes) + geom_bar(aes(x=species)) + coord_flip() + ggtitle("Project Total") + labs(x="Label") + theme(text = element_text(size=20))
65+
# }
66+
67+
species_colors <- colorFactor(palette = c("yellow", "blue",
68+
"#ff007f", "brown",
69+
"purple", "white"),
70+
domain = c("Great Egret", "Great Blue Heron",
71+
"Roseate Spoonbill", "Wood Stork",
72+
"Snowy Egret", "White Ibis"),
73+
ordered=TRUE)
74+
75+
totals_plot <- function(selected_boxes) {
76+
ggplot(selected_boxes, aes(x = species, fill = species_colors(species))) +
77+
geom_bar() + coord_flip() + ggtitle("Project Total") + labs(x = "Label") +
78+
scale_fill_identity(guide = "none") +
79+
theme(
80+
text = element_text(size = 20),
81+
panel.background = element_rect(fill = "#add8e6")
82+
)
6483
}
6584

6685
site_totals<-function(selected_boxes){
@@ -77,21 +96,20 @@ site_phenology<-function(selected_boxes){
7796
theme(text = element_text(size=20))
7897
}
7998

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)
99+
plot_annotations<-function(selected_boxes, MAPBOX_ACCESS_TOKEN) {
100+
pal <- colorFactor(palette = "Dark2", domain = selected_boxes$species)
101+
102+
# Convert polygons to centroids
103+
selected_centroids <- st_centroid(selected_boxes)
104+
selected_centroids <- st_transform(selected_centroids, 4326)
87105

88-
#Create mapbox tileset
89-
mapbox_tileset<-unique(selected_centroids$tileset_id)
90-
mapbox_tileset<-paste("bweinstein.",mapbox_tileset,sep="")
106+
# Create mapbox tileset
107+
mapbox_tileset <- unique(selected_centroids$tileset_id)
108+
mapbox_tileset <- paste("bweinstein.", mapbox_tileset, sep = "")
91109

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))
110+
m <- leaflet(data = selected_centroids) %>%
111+
addProviderTiles("MapBox", options = providerTileOptions(id = mapbox_tileset, minZoom = 8, maxNativeZoom = 24, maxZoom = 24, accessToken = MAPBOX_ACCESS_TOKEN)) %>%
112+
addCircles(stroke = T, color=~pal(species),fillOpacity = 0.1, radius = 0.25, popup = ~htmlEscape(label))
95113
return(m)
96114
}
97115

@@ -152,21 +170,13 @@ nest_history<-function(dat){
152170
theme(axis.text.x = element_text(angle = -90),text = element_text(size=20))
153171
}
154172

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-
163173
plot_nests<-function(df, bird_df, MAPBOX_ACCESS_TOKEN){
164174
mapbox_tileset<-unique(bird_df$tileset_id)[1]
165175
mapbox_tileset<-paste("bweinstein.",mapbox_tileset,sep="")
166176

167177
m<-leaflet(data=df) %>%
168178
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=":"))) %>%
179+
addCircles(stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs,2),nest_id,sep=":"))) %>%
170180
addCircles(data = bird_df, stroke = T, fillOpacity = 0, radius = 0.2, color = ~species_colors(label),
171181
popup = ~htmlEscape(paste(round(score,2), bird_id, sep=":")))
172182
return(m)
@@ -193,7 +203,7 @@ update_nests<-function(mapbox_tileset, df, bird_df, show_nests, show_birds,
193203
}
194204
if (show_nests) {
195205
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=", ")))
206+
addCircles(data=df,stroke = T,fillOpacity = 0.1,radius = 0.5,popup = ~htmlEscape(paste(round(sum_top1/num_obs,2),nest_id,sep=", ")))
197207
}
198208
if (show_birds) {
199209
map <- map %>%
@@ -215,10 +225,9 @@ zooniverse_complete<-function(){
215225
subject_data<-read.csv("data/everglades-watch-subjects.csv")
216226
raw_annotations<-read.csv("data/parsed_annotations.csv")
217227
subject_data$Site<-sapply(subject_data$metadata, function(x) str_match(gsub('\"', "", x, fixed = TRUE),"site:(\\w+)")[,2])
218-
219228
#images per site
220229
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)) %>%
221230
tidyr::spread(annotated,n, fill=0) %>% mutate(Percent_Complete=`TRUE`/(`TRUE`+`FALSE`)*100)
222231
p<-ggplot(completed,aes(x=Site,y=Percent_Complete)) + coord_flip() + geom_bar(stat="identity") + labs(y="Annotated (%)",x="Subject Set")
223232
return(p)
224-
}
233+
}

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)