-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathapp.R
76 lines (59 loc) · 1.81 KB
/
app.R
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(leaflet)
library(spData)
library(dplyr)
# Define UI for application that filters map points based on year and minimum population
ui <- fluidPage(
# Application title
titlePanel("World Population Over Time"),
# Sidebar with a slider input for year, numeric input for population
sidebarLayout(
sidebarPanel(
sliderInput("year",
"Year",
min = 1950,
max = 2030,
step = 5,
sep = "",
value = 1950),
numericInput("pop_min",
"Minimum Population (in millions)",
min = 1,
max = 20,
value = 10)
),
# Show the map and table
mainPanel(
# plotOutput("distPlot"),
leafletOutput("map"),
dataTableOutput("table")
)
)
)
# Define server logic required to draw a map and table
server <- function(input, output) {
output$map <- renderLeaflet({
pop_by_year <- filter(urban_agglomerations,
year == input$year,
population_millions > input$pop_min)
leaflet(data = pop_by_year) %>%
addTiles() %>%
addMarkers()
})
output$table <- renderDataTable({
pop_by_year <- filter(urban_agglomerations,
year == input$year,
population_millions > input$pop_min)
pop_by_year
})
}
# Run the application
shinyApp(ui = ui, server = server)