-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
87 lines (74 loc) · 3.31 KB
/
server.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
library(shiny)
library(tidyverse)
library(leaflet)
library(rgdal)
library(htmltools)
states <- rgdal::readOGR("States.JSON.txt", "OGRGeoJSON")
state_specialty <- read.table("specialty_by_state_data.csv", header = TRUE, sep = ',')
regional_specialty <- read.table("regional_specialty_data.csv", header = TRUE, sep = ',')
States_physicians<- read.csv("specialty_by_state_data.csv")
per_capita <- read.csv("Per10KData.csv", header = TRUE, sep = ',')
# Define server logic required to draw a histogram
function(input, output) {
output$specialty_plot <- renderPlot({
# draw the barplot with the specialties as x
gather(state_specialty, key = "specialty", value = "value", Psychiatry:Other) %>%
filter(Location == input$state) %>%
ggplot(aes(specialty, value)) + geom_bar(stat = 'identity', color = "slateblue3", fill = "slateblue1")+ theme(axis.text.x = element_text(angle = 60, hjust = 1), panel.background = element_rect(fill = "lavender"))
})
output$regional_plot <- renderPlot({
#draw the barplot with specialties as x and regions as select input
gather(regional_specialty, key = "specialty", value = "value", Psychiatry:Other) %>%
filter(Location == input$region) %>%
ggplot(aes(specialty, value)) + geom_bar(stat= 'identity', color = "slateblue3", fill = "slateblue1") + theme(axis.text.x = element_text(angle = 60, hjust = 1), panel.background = element_rect(fill = "lavender"))
})
output$population_plot <- renderPlot({
#draw the barplot with the states as x
state_specialty[-1,] %>%
ggplot(aes_string("Location", input$specialty)) + geom_bar(stat = 'identity', color = "slateblue3", fill = "slateblue1") + theme(axis.text.x = element_text(angle = 60, hjust = 1), panel.background = element_rect(fill = "lavender"))
})
#################
"Heat Map of US States with physicians per capita"
output$Physician_Heatmap <-renderLeaflet({
joinedData<-left_join(states@data, per_capita, by= c("NAME"="Location"))
states@data <- joinedData
pal1 <- colorBin(
palette = c("cyan", "darkblue"),
domain = states@data$CapitaRatio,
bins = 6,
pretty = TRUE,
na.color = "#808080",
alpha = FALSE,
reverse = FALSE)
labels1 <- sprintf(
"<strong>%s</strong><br/>%g Physicians",
states@data$NAME,
states@data$CapitaRatio
) %>%
lapply(htmltools::HTML)
leaflet(data = states) %>%
addTiles %>%
addPolygons(fillColor = ~pal1(CapitaRatio),
fillOpacity = 0.8,
color = "black",
weight = 1,
highlight = highlightOptions(
weight = 5,
color = "black",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels1,
labelOptions = labelOptions(
style = list("font-weight" = "normal",
padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal1,
values = ~CapitaRatio,
opacity = 0.7,
title = NULL,
position = "bottomright") %>%
setView(lat = 38.0110306, lng = -110.4080342, zoom = 3)
})
}