Skip to content

Commit 04c9fc1

Browse files
committed
reset button and treecover layer
1 parent 896dd4b commit 04c9fc1

3 files changed

Lines changed: 53 additions & 28 deletions

File tree

Shiny/server.R

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
library(shiny)
12+
library(shinyjs)
1213
library(gsgsim)
1314
library(leaflet)
1415
library(raster)
@@ -17,16 +18,25 @@ library(DT)
1718

1819
options(shiny.error = browser)
1920
# Define server logic required to generate GSG
20-
shinyServer(function(input, output) {
21+
shinyServer(function(input, output, session) {
2122

2223

2324
output$map <- renderLeaflet({
24-
leaflet() %>%
25-
addProviderTiles("OpenStreetMap")
25+
leaflet() %>%
26+
addTiles() %>%
27+
addWMSTiles(
28+
"http://globalforestwatch-624153201.us-west-1.elb.amazonaws.com:80/arcgis/services/TreeCover2000/ImageServer/WMSServer",
29+
layers="0",
30+
options = WMSTileOptions(format = "image/png", transparent = TRUE)
31+
) #%>% addWMSLegend("http://globalforestwatch-624153201.us-west-1.elb.amazonaws.com:80/arcgis/services/TreeCover2000/ImageServer/WMSServer?request=GetLegendGraphic%26version=1.3.0%26format=image/png%26layer=0",
32+
#position = 'bottomright')
2633

27-
})
2834

35+
})
2936

37+
observeEvent(input$reset_input,{
38+
shinyjs::reset("settings")
39+
})
3040

3141
observeEvent(
3242
# Take a dependency on input$goButton
@@ -95,7 +105,7 @@ observeEvent(
95105
clearShapes() %>%
96106

97107
addPolygons(data = bnd, color = "#444444", weight = 1, smoothFactor = 0.5,
98-
opacity = 0.4, fillOpacity = 0.5) %>%
108+
opacity = 0.3, fillOpacity = 0.5) %>%
99109

100110
addCircles(data=gsg, weight = 3, radius=40,
101111
color="#CD0000", stroke = TRUE, fillOpacity = 0.9) %>%
@@ -114,7 +124,7 @@ observeEvent(
114124
output$mytable <- DT::renderDataTable(
115125
DT::datatable(as.data.frame(gsg), options = list(pageLength = 25))
116126
)
117-
127+
updateNavbarPage(session, "nav", selected="gomap")
118128

119129
}
120130
})

Shiny/styles.css

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
input[type="number"] {
2-
max-width: 100%;
1+
/* for computer */
2+
div.outer {
3+
height: calc(100vh - 80px);
4+
padding: 0;
5+
margin: 0;
6+
min-height: 500px
37
}
48

5-
div.outer {
9+
@media all and (max-width:768px){
10+
/* for mobile */
11+
div.outer {
612
position: fixed;
7-
top: 41px;
13+
top: 70px;
814
left: 0;
915
right: 0;
1016
bottom: 0;
1117
overflow: hidden;
1218
padding: 0;
1319
}
20+
}
1421

1522
/* Customize fonts */
1623
body, label, input, button, select {
@@ -46,4 +53,9 @@ h1, h2, h3, h4 { font-weight: 400; }
4653
/* If not using map tiles, show a white background */
4754
.leaflet-container {
4855
background-color: white !important;
56+
}
57+
58+
button#reset_input:hover {
59+
background-color:#da1313;
60+
}
4961
}

Shiny/ui.R

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,37 @@
88
#
99

1010
library(shiny)
11+
library(shinyjs)
1112
library(raster)
1213
library(leaflet)
1314
library(DT)
1415

15-
# Define UI for application that draws a histogram
16-
navbarPage("Global Sampling Grid",
17-
id="nav",
18-
19-
2016

2117

22-
tabPanel("Interactive map",
23-
div(class="outer",
18+
ui <- fluidPage(
19+
shinyjs::useShinyjs(),
2420

25-
tags$head(
26-
# Include our custom CSS
27-
includeCSS("styles.css")
28-
29-
),
21+
# Define UI for application that draws a histogram
22+
navbarPage("Global Sampling Grid", id="nav",
3023

24+
tabPanel("Interactive map", value="gomap",
3125

32-
leafletOutput("map", width="100%", height="100%")
26+
div(class="outer",
27+
tags$head(
3328

34-
)),
29+
# Include our custom CSS
30+
includeCSS("styles.css")
31+
),
32+
leafletOutput("map")
33+
)
34+
),
3535

36-
tabPanel("Data Explorer", DT::dataTableOutput('mytable')),
36+
tabPanel("Data Explorer",
37+
DT::dataTableOutput('mytable')
38+
),
3739

38-
tabPanel("GSG Settings",
40+
tabPanel("GSG Settings",
41+
div(id="settings",
3942
fluidRow(
4043
column(4,
4144
# Inputs
@@ -92,6 +95,6 @@ tabPanel("GSG Settings",
9295
downloadButton("download", "Download")
9396

9497
)
95-
)
98+
))
9699

97-
))
100+
)))

0 commit comments

Comments
 (0)