-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp3.R
More file actions
91 lines (76 loc) · 3.04 KB
/
app3.R
File metadata and controls
91 lines (76 loc) · 3.04 KB
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
# App developed my Data Cube Solutions
# contactdatacube@gmail.com / molo.andrew@gmail.com
# Data is reproducible
# Link to the online dataset
library(easypackages)
libraries("shiny","shinydashboard","tidyverse","lubridate", "plotly","Rcpp")
theme_set(theme_minimal())
town <- unique(medicalPractitioners$Town)
ui <- fluidPage(
dashboardPage(skin = "yellow",
dashboardHeader(
title = "KMPDC Data Dashboard",
titleWidth = 250
),
dashboardSidebar(
sidebarMenu(
sidebarSearchForm(textId = "Search", buttonId = "searchTown",
label = "Search city/town")
)
),
dashboardBody(
fluidRow(
tabBox(width = 12, height = NULL, selected = "Count of Practitioners",
tabPanel("Count of medical practitioners", plotlyOutput("practitioners_count")),
tabPanel("Number of qualifications per medical practitioners", plotlyOutput("qualifications_count")),
tabPanel("Top specialties of medical practitioners", plotlyOutput("specialityCount"))
)
)
) # End of dashboardBody()
) # End of dashboardPage()
)
server <- function(input, output) {
# Make a data frame that changes when the user chooses something
filtered_data = reactive({
df = medicalPractitioners %>%
# filter(Town %in% toupper(input$Search)) %>%
dplyr::filter(Town == toupper(input$Search)) %>%
# group_by(`Year Range`) %>%
# summarise(count = n())
df
})
# Count of Medical Practitioners Plot - Based on filtered Data
filteredMP = reactive({
df = filtered_data()
df %>%
group_by(`Year Range`) %>%
summarise(count = n()) %>%
ggplot(aes(`Year Range`, count)) +
geom_line(aes(group = 1),color="#aa2b1d", size=1) +
geom_point(size=4, color="#28527a") +
labs(title = "Count of Medical Practitioners in Kenya",
subtitle = "Data from 1978 to 2020",
caption = "Source: medicalboard.co.ke",
x="") +
theme(
plot.title = element_text(color = "#23689b", size = 20, face = "bold",hjust = 0.5),
plot.subtitle = element_text(color = "#161d6f", size = 13, face = "bold",hjust = 0.5),
plot.caption = element_text(color = "#0f1123", size = 10, face = "italic"),
axis.text.x = element_text(face = "bold", size = 12),
axis.text.y = element_text(face = "bold", size = 12)
) +
geom_label(aes(label=count),
nudge_x = 0.1,
nudge_y = 0.2,
size=5)
})
# Render Plots in server function
output$practitioners_count <- renderPlot({ # render the count plot with an error if there is no data
validate(
need(nrow(filtered_data()) > 0, 'Please select a city')
)
filteredMP()
})
}
# Run the application
shinyApp(ui = ui, server = server)