-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
99 lines (75 loc) · 2.39 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
library(tidyverse)
library(shiny)
library(shinythemes)
library(leaflet)
# reading in clean data
meteorites <- read_csv("data/meteorite_landings_clean_data.csv")
# Shiny app
## User Interface
ui <- fluidPage(
theme = shinytheme("spacelab"),
titlePanel(
fluidRow(
column(1, "Meteorites"),
column(1, img(height = 105, width = 200, src = "nasa-logo-web-rgb.png"))
)
),
sidebarLayout(
sidebarPanel(
radioButtons("fall_found_button",
"Recorded as:",
choices = c("Fell", "Found")
),
sliderInput("year_slider",
"Year recorded:",
min = 1583, max = 2013, value = 430,
sep = "" #getting rid of the default "," separator (eg 1,234)
),
actionButton("update",
"Press for more details and location"),
hr(),
plotOutput("meteorites_histogram")
),
mainPanel(
DT::dataTableOutput("table_output"),
leafletOutput("meteorites_map")
)
)
)
## Server
server <- function(input, output) {
### histogram showing the number of reported meteorites each year
output$meteorites_histogram <- renderPlot({
meteorites %>%
ggplot() +
aes(x = year) +
geom_histogram(bins = 500, fill = "#0b3d91") +
theme_light() +
labs(
y = "meteorites",
title = "\n\n Number of meteorites reported each year"
)
})
### setting up the reactive function, to only get the filtered results after pressing action button
meteorites_filtered <- eventReactive(input$update, {
meteorites %>%
filter(fall == input$fall_found_button) %>%
filter(year == input$year_slider)
})
### creating an interactive table that gives information about filtered meteorites
### displays after pressing action button
output$table_output <- DT::renderDataTable({
meteorites_filtered() %>%
select(-id, -fall, -year) %>%
rename("mass (g)" = mass_g)
})
### creating an interactive map that displays location of filtered meteorites
### displays after pressing action button
output$meteorites_map <- renderLeaflet({
meteorites_filtered() %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(lat = ~latitude, lng = ~longitude, popup = ~name)
})
}
shinyApp(ui = ui, server = server)