forked from nhs-r-community/shiny-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_and_e_code_first.R
69 lines (48 loc) · 1.52 KB
/
a_and_e_code_first.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
# right at the top
library(tidyverse)
library(leaflet)
load(url("https://github.com/nhs-r-community/shiny-training/blob/main/a_and_e_first/ae_attendances.RData?raw=true"))
# UI
# select date range
sidebarLayout(
sidebarPanel(
dateRangeInput(), # as.Date("2016-04-01") to as.Date("2019-03-01")
selectInput(...,
multiple = TRUE), # select trust
),
# inside main panel
plotOutput(), # place graph in tab one
leafletOutput() # place map in tab two
mainPanel(
tabsetPanel(
tabPanel("Label", outputFunction("nameOfOutput")),
tabPanel("Label2", outputFunction2("nameOfOutput2"))
)
)
)
# server code- complete
server <- function(input, output) {
filter_data <- reactive({
sample_trusts <- ae_attendances %>%
filter(period >= input$date[1], period <= input$date[2]) %>%
arrange(Name)
})
output$trustMap <- renderLeaflet({
filter_data() %>%
leaflet() %>%
addTiles() %>%
setView(lng = -2, lat = 53, zoom = 7) %>%
addCircleMarkers(lng = ~ lon, lat = ~ lat, weight = 1,
radius = ~ attendances/ 1000,
layerId = ~org_code)
})
output$graph <- renderPlot({
graph_data <- filter_data() %>%
filter(Name %in% input$trust)
graph_data %>%
group_by(period, Name) %>%
summarise(mean_attendance = mean(attendances)) %>%
ggplot(aes(x = period, y = mean_attendance)) +
geom_line() + facet_wrap(~ Name, scales = "free")
})
}