-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
executable file
·56 lines (47 loc) · 2.51 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
function(input, output, session) {
#Sets the necessary filters read from the UI
filteredArticles <- function(){return(articles)} #reactive({
# newFilter <- function(mapFilter,hideCountry,countryFilter,crossFilterType,hideCrossCountry,countryCrossFilter,citation,year,gsRank,authors,university,publisher,keywordList){
# newFilter(input$MapFilter,input$hideCountry,input$countryFilter,input$FilterType,input$HideCrossCountry,input$countryCrossFilter,input$citations,input$Year,input$GSRank,input$Authors,input$University,input$Publisher,input$KeywordList) %>% data.frame()
# })
filteredData <- reactive({
#newFilter <- function(mapFilter,hideCountry,countryFilter,crossFilterType,hideCrossCountry,countryCrossFilter,citation,year,gsRank,authors,university,publisher,keywordList){
data <- getStat(filteredArticles(), input$MapFilter,input$hideCountry,input$countryFilter)
})
output$map <- renderLeaflet({
# Use leaflet() here, and only include aspects of the map that
# won't need to change dynamically (at least, not unless the
# entire map is being torn down and recreated).
leaflet(filteredData()) %>%
addProviderTiles("CartoDB.Positron") %>%
setView(50, 0, zoom = 2)
})
output$table <- DT::renderDataTable(DT::datatable({
filteredArticles()
}))
#HOW DOES ALL OF THIS WORK??
#create reactive colorVariable, which updates the color palette based on the type of map chosen.
colorVariable <- reactive({
filteredData()@data[["Count"]]
#filteredData[["Count"]]
})
# This reactive expression represents the palette function,
# which changes as the user makes selections in UI.
colorpal <- reactive({
colorBin("YlOrRd", colorVariable()) #you can change the color palette here.
})
#update map based on changed inputs figure out how this is working and see if its similar to the diagram!!!
observe({
pal <- colorpal() #set the variable pal equal to the reactive variable colorpal.
#Where the fourth option breaks!
colorBy <- "Count"
leafletProxy("map", data = filteredData()) %>%
clearShapes() %>%
clearControls() %>%
addPolygons(stroke=FALSE, smoothFactor=0.2,
color = ~pal(filteredData()@data[,colorBy]),
opacity = 1,
popup = ~paste("<strong>",colorBy,":</strong>",filteredData()@data[,colorBy], "<strong>Country:</strong>",NAME)) %>%
addLegend(title=colorBy, pal=colorpal(), values=filteredData()@data[,colorBy], position="bottomleft")
})
}