Ifeanyi commited on
Commit
5c9a01f
·
verified ·
1 Parent(s): e8cc9de

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +157 -51
app.R CHANGED
@@ -1,65 +1,171 @@
1
  library(shiny)
2
- library(shinyjs)
3
- library(shinyWidgets)
4
- library(shinythemes)
5
- library(GWalkR)
6
-
7
-
8
- ui <- fluidPage(
9
- includeCSS("styles.css"),
10
- useShinyjs(),
11
- setBackgroundColor(color = c("white","#007acc"),gradient = c("linear","radial")),
12
- title = "Data Explorer",
13
- theme = shinytheme("cerulean"),
14
- tags$h3(id = "title", tags$strong("Graphic-Walker Data Explorer"),style = "text-align:center;color:#007acc;"),
15
- tags$a(href = "https://github.com/Ifeanyi55", tags$strong("Maintainer"),target = "_blank",style = "text-decoration:none;color:#007acc;margin-left:1250px;margin-bottom:1000px"),
16
- br(),br(),
17
- sidebarLayout(sidebarPanel = "",
18
- mainPanel(align = "center",
19
- width = 12,
20
- fileInput("target_upload",h5(strong("Click to Upload CSV File"),style = "color:#007acc;"),
21
- accept = c("text/csv"),
22
- buttonLabel = strong("Select File",style = "color:#007acc;"),
23
- placeholder = "No file selected"),
24
- actionButton("reset",strong("Reset"),icon = icon("refresh"),style = "color:#007acc;"),
25
- a(href = "https://github.com/Kanaries/GWalkR",h6(strong("Learn More"),style = "color:#007acc;margin-left:-1220px;margin-top:-170px;font-size:15px;"),target = "_blank",style = "text-decoration: none;"),
26
- gwalkrOutput(outputId = "explorer",width = "101%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  )
28
- )
 
29
  )
30
 
31
- server <- function(input,output,session){
32
-
33
- # increase file upload size to 100MB
34
- options(shiny.maxRequestSize = 100 * 1024^2)
35
-
36
- file_upload <- reactive({
37
- inFile <- input$target_upload
38
- if(is.null(inFile)){return(NULL)}
39
- data <- read.csv(inFile$datapath,header = TRUE,sep = ",")
40
- return(data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  })
42
-
43
-
44
-
45
- output$explorer <- renderGwalkr({
46
  tryCatch(
47
  {
48
-
49
- gwalkr(file_upload())
50
-
 
51
  },
52
- error = function(e){
53
- message("Could not display interface")
 
54
  }
55
  )
56
  })
57
-
58
- # refresh app
59
- observeEvent(input$reset,{
60
- runjs("location.reload();")
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  })
62
  }
63
 
64
- shinyApp(ui,server)
65
-
 
1
  library(shiny)
2
+ library(bs4Dash)
3
+ library(leaflet)
4
+ library(highcharter)
5
+ library(reactable)
6
+ library(reactablefmtr)
7
+ library(data.table)
8
+ library(dplyr)
9
+ library(lubridate)
10
+
11
+
12
+ # load map function
13
+ source("Map.R")
14
+
15
+ # load plot function
16
+ source("Plot.R")
17
+
18
+ # load table function
19
+ source("Table.R")
20
+
21
+ # load dataset
22
+ bio_poland <- fread("poland.csv")
23
+
24
+ # filter dataset and select relevant columns
25
+ poland_bio <- bio_poland |>
26
+ filter(vernacularName != "") |>
27
+ select(
28
+ vernacularName,
29
+ longitudeDecimal,
30
+ latitudeDecimal,
31
+ individualCount,
32
+ eventDate,
33
+ locality
34
+ ) |>
35
+ mutate(eventDate = as_date(eventDate))
36
+
37
+
38
+ # add blanks to vector of choices so that the widget loads blank
39
+ choices2 <- unique(poland_bio$vernacularName)
40
+
41
+
42
+ # create dashboard brand
43
+ dash_title <- dashboardBrand(
44
+ title = "Biodiversity in Poland",
45
+ color = "primary",
46
+ href = "https://www.gbif.org/occurrence/search?q=Poland&country=PL",
47
+ image = "bird_2.jpg"
48
+ )
49
+
50
+ # define UI
51
+ ui <- dashboardPage(
52
+ title = "Biodiversity",
53
+ scrollToTop = T,
54
+ help = NULL,
55
+ dark = NULL,
56
+ header = dashboardHeader(title = dash_title),
57
+ sidebar = dashboardSidebar(disable = T),
58
+ footer = dashboardFooter(left = "Source: Global Biodiversity Informational Facility"),
59
+ body = dashboardBody(
60
+ tags$style(HTML("
61
+ .box {
62
+ border: 2px solid #007bff !important;
63
+ box-shadow: none !important;
64
+ }
65
+ ")),
66
+ fluidRow(
67
+ column(
68
+ 12,
69
+ selectizeInput("vernacular",
70
+ label = strong("Vernacular Name"),
71
+ choices = choices2,
72
+ selected = "Mandarin Duck",
73
+ width = "100%"
74
+ )
75
+ )
76
+ ),
77
+ fluidRow(
78
+ box(
79
+ class = "box",
80
+ title = "Map of Observations",
81
+ width = 12,
82
+ status = "primary",
83
+ solidHeader = T,
84
+ leafletOutput("map_plot"), elevation = 4
85
+ )
86
+ ),
87
+ fluidRow(
88
+ box(
89
+ class = "box",
90
+ title = "Plot of Observation Over time",
91
+ status = "primary",
92
+ solidHeader = T,
93
+ highchartOutput("chart"), elevation = 4
94
+ ),
95
+ box(
96
+ class = "box",
97
+ title = "Observation Data",
98
+ status = "primary",
99
+ solidHeader = T,
100
+ reactableOutput("table", height = 400),
101
+ elevation = 4
102
+ )
103
  )
104
+ ),
105
+ fullscreen = T
106
  )
107
 
108
+ # Define server logic required to draw a histogram
109
+ server <- function(input, output, session) {
110
+ # make input values reactive and return the defaults if both input values are NULL
111
+ input_vernacular <- reactive({
112
+ input$vernacular %||% "Mandarin Duck"
113
+ })
114
+
115
+
116
+ # render map
117
+ output$map_plot <- renderLeaflet({
118
+ req(poland_bio)
119
+ tryCatch(
120
+ {
121
+ mapData(
122
+ df = poland_bio,
123
+ vernacular = input_vernacular()
124
+ )
125
+ },
126
+ error = function(e) {
127
+ leaflet() |>
128
+ addTiles() |>
129
+ addPopups(lng = 0, lat = 0, popup = "No data available for the selected filters")
130
+ }
131
+ )
132
  })
133
+
134
+ # render chart
135
+ output$chart <- renderHighchart({
136
+ req(poland_bio)
137
  tryCatch(
138
  {
139
+ plotData(
140
+ df = poland_bio,
141
+ vernacular = input_vernacular()
142
+ )
143
  },
144
+ error = function(e) {
145
+ highchart() |>
146
+ hc_title(text = "No data available for the selected filters")
147
  }
148
  )
149
  })
150
+
151
+ # render table
152
+ output$table <- renderReactable({
153
+ req(poland_bio)
154
+ tryCatch(
155
+ {
156
+ tableFunction(
157
+ df = poland_bio,
158
+ vernacular = input_vernacular()
159
+ )
160
+ },
161
+ error = function(e) {
162
+ reactable(data.frame(
163
+ Message = "No data available for the selected filters"
164
+ ))
165
+ }
166
+ )
167
  })
168
  }
169
 
170
+ # Run the application
171
+ shinyApp(ui = ui, server = server)