Created
March 22, 2016 18:27
-
-
Save monspo1/52d236623abdcea5c498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server <- function(input, output) { | |
# ... | |
# ... Other functions are intentionally omitted for brevity ... | |
# ... | |
#//////////////////////////////////////////////////////////////////////////////// | |
# reactive function for comparison Map 1 and comparison table 1 | |
#//////////////////////////////////////////////////////////////////////////////// | |
updateInputDataForMapByJobTitle1 <- reactive({ | |
# Data filtering from the orignal data 'salary_refined' | |
dataFilteredForMapByJobTitle1 <- salary_refined | |
dataFilteredForMapByJobTitle1 <- dataFilteredForMapByJobTitle1 %>% | |
group_by(WORK_STATE, JOB_TITLE_SUBGROUP) %>% | |
summarise(AVG_SALARY= round(mean(PAID_WAGE_PER_YEAR), 2), NUM_POS = n()) | |
if(input$singleSelectForJobTitleForComparison1 != ""){ | |
dataFilteredForMapByJobTitle1 <- dataFilteredForMapByJobTitle1[(input$singleSelectForJobTitleForComparison1 == dataFilteredForMapByJobTitle1$JOB_TITLE_SUBGROUP),] | |
} | |
dataFilteredForMapByJobTitle1 # return the filtered data | |
}) | |
#//////////////////////////////////////////////////////////////////////////////// | |
# comparison Map 1 (googleVis) | |
#//////////////////////////////////////////////////////////////////////////////// | |
output$myGvisMap1 <- renderGvis({ | |
# call the updateInputDataForMapByJobTitle1() function to get the filtered data | |
# This function call to updateInputDataForMapByJobTitle1() enables to synchronously react user input and show the updated results. | |
mapData <- updateInputDataForMapByJobTitle1() | |
# Render the map using the filtered data | |
gvisGeoChart(mapData, locationvar= "WORK_STATE", colorvar="AVG_SALARY", | |
options=list(region="US", displayMode="regions", resolution="provinces", | |
width="100%", | |
backgroundColor="gray" | |
) | |
) | |
}) | |
#//////////////////////////////////////////////////////////////////////////////// | |
# Comparison Map 1 | |
#//////////////////////////////////////////////////////////////////////////////// | |
output$myComparisonTableByJobTitle1 <- DT::renderDataTable(DT::datatable({ | |
# call the updateInputDataForMapByJobTitle1() function to get the filtered data | |
# This function call to updateInputDataForMapByJobTitle1() enables to synchronously react user input and show the updated results. | |
dataForDTable1 <- updateInputDataForMapByJobTitle1() | |
# Change the call names | |
colnames(dataForDTable1) <- c("STATE","JOB_TITLE","AVG_SALARY", "JOBS") | |
dataForDTable1 # filtered data for the dataTable | |
}, rownames = FALSE, extensions = c('ColVis','ColReorder','Scroller'), options = list( | |
deferRender = TRUE, | |
searching = T, | |
dom = 'RC<"clear">lfrtip', | |
colVis = list(activate = 'mouseover'), | |
lengthMenu = list(c(10, 5, 15, 25, 25, 50, 100), c('10', '5', '15', '20', '25','50','100')) | |
)) %>% formatCurrency(c('AVG_SALARY'), "$") ) | |
# ... | |
# ... Other functions are intentionally omitted for brevity ... | |
# ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment