Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny app tweaks #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
48 changes: 31 additions & 17 deletions dataTool/ancDataTool/app.R → shinyapp/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ library(magrittr)
library(dplyr)
library(ggplot2)

electionHistoryTable = read_csv('election_history_R.csv')
electionHistoryTable = read_csv('../cleaned_data/2012_2018_ancElection_contest.csv')
electionHistoryTable %<>%
mutate(ward = as.factor(ward),smd = as.factor(smd),anc=as.factor(anc),year=as.integer(year)) %>%
select(year,ward,anc,smd,smd_anc_votes,winner_votes) %>%
mutate(winnerPct = winner_votes / smd_anc_votes)


# Define UI for application that draws a histogram
ui <- navbarPage("Historical ANC Data Dashboard",

Expand All @@ -29,7 +30,8 @@ ui <- navbarPage("Historical ANC Data Dashboard",

uiOutput("smdPlot_select_ward"),
uiOutput("smdPlot_select_anc"),
uiOutput("smdPlot_select_smd")
uiOutput("smdPlot_select_smd"),
checkboxInput("smdPlot_select_all", "Select All SMDs", value=FALSE)
),

# Show a plot of the generated distribution
Expand Down Expand Up @@ -63,42 +65,54 @@ ui <- navbarPage("Historical ANC Data Dashboard",
server <- function(input, output,session) {

smdPlotTable <- reactive({


req(input$smdSelection)

electionHistoryTable %>%
filter(ward==input$wardSelection) %>%
filter(anc == input$ancSelection) %>%
filter(smd %in% input$smdSelection)

})

distHistTable <- reactive({

electionHistoryTable %>% mutate(year = as.factor(year))
})


observe({
if (input$smdPlot_select_all == TRUE){
updateCheckboxGroupInput(session, "smdSelection", choices=choice_smd(),
selected=choice_smd())
} else{
updateCheckboxGroupInput(session, "smdSelection", choices=choice_smd(),
selected=c())
}
})

output$smdPlot_select_ward <- renderUI({

selectizeInput('wardSelection','Select Ward',choices=c("select" = "",levels(electionHistoryTable$ward)))
selectizeInput('wardSelection','Select Ward',choices=levels(electionHistoryTable$ward))
})


output$smdPlot_select_anc <- renderUI({

choice_anc <- reactive({
electionHistoryTable %>% filter(ward==input$wardSelection) %>% pull(anc) %>% unique() %>% as.character()
req(input$wardSelection)
electionHistoryTable %>% filter(ward==input$wardSelection) %>% pull(anc) %>% unique() %>% as.character()
})
selectizeInput('ancSelection','Select ANC',choices=c("select" = "",choice_anc()))
})

output$smdPlot_select_smd <- renderUI({

choice_smd <- reactive({
output$smdPlot_select_anc <- renderUI({

electionHistoryTable %>% filter(ward==input$wardSelection) %>% filter(anc == input$ancSelection) %>% pull(smd) %>% unique() %>% as.character()
selectizeInput('ancSelection','Select ANC',choices=choice_anc())
})

choice_smd <- reactive({
req(input$ancSelection)
electionHistoryTable %>% filter(ward==input$wardSelection) %>% filter(anc == input$ancSelection) %>% pull(smd) %>% unique() %>% as.character()
})
checkboxGroupInput("smdSelection",'Select SMD',choices = choice_smd(),selected = 1)

output$smdPlot_select_smd <- renderUI({

checkboxGroupInput("smdSelection",'Select SMD',choices = choice_smd())
})


Expand Down