-
Notifications
You must be signed in to change notification settings - Fork 2
/
_06-shiny.Rmd
54 lines (37 loc) · 1.36 KB
/
_06-shiny.Rmd
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
# Shiny interactive map applications {#shiny}
Use of the shiny package to make interactive applications displaying maps.
We start with a very simple example showing how you can create a small application that allows a user to choose from a list of countries and then displays the outline of that country on a map.
[andy (or anyone else) to look at best ways of demoing shinyapps in a book]
```{r shiny1, eval=FALSE}
# save this code in a single file called app.r
# then the shiny app can be run from RStudio using the 'Run' button
# (above the text editor window)
# or can just copy & paste code into the console
library(afrilearndata)
library(dplyr)
library(mapview)
library(leaflet)
# User Interface
ui <- bootstrapPage(
# allow user to choose a country
selectInput('country_choice',
label='choose a country',
choices = sort(africountries$name)),
# plot map
leafletOutput("serve_map")
)
# server code (does things requested by the UI)
server <- function(input, output) {
output$serve_map <- renderLeaflet({
# filter
selected_country <- dplyr::filter(africountries, name==input$country_choice)
mapplot <- mapview(selected_country, zcol="name")
mapplot@map
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)
```
## Further resources
## Summary
## Exercise solutions {#solutions_ch5}