From a2c66a9f291ca3469bdb61d2280f46e0f4062456 Mon Sep 17 00:00:00 2001 From: Austen Mack-Crane Date: Wed, 4 Mar 2020 15:29:16 -0500 Subject: [PATCH 1/2] simplified shiny directory path --- {dataTool/ancDataTool => shinyapp}/.Rhistory | 0 {dataTool/ancDataTool => shinyapp}/app.R | 0 {dataTool/ancDataTool => shinyapp}/election_history_R.csv | 0 .../rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {dataTool/ancDataTool => shinyapp}/.Rhistory (100%) rename {dataTool/ancDataTool => shinyapp}/app.R (100%) rename {dataTool/ancDataTool => shinyapp}/election_history_R.csv (100%) rename {dataTool/ancDataTool => shinyapp}/rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf (100%) diff --git a/dataTool/ancDataTool/.Rhistory b/shinyapp/.Rhistory similarity index 100% rename from dataTool/ancDataTool/.Rhistory rename to shinyapp/.Rhistory diff --git a/dataTool/ancDataTool/app.R b/shinyapp/app.R similarity index 100% rename from dataTool/ancDataTool/app.R rename to shinyapp/app.R diff --git a/dataTool/ancDataTool/election_history_R.csv b/shinyapp/election_history_R.csv similarity index 100% rename from dataTool/ancDataTool/election_history_R.csv rename to shinyapp/election_history_R.csv diff --git a/dataTool/ancDataTool/rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf b/shinyapp/rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf similarity index 100% rename from dataTool/ancDataTool/rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf rename to shinyapp/rsconnect/shinyapps.io/fourthfloordoug/ancdatatool.dcf From 83c022a002467f88f74b5b5e8150ca7ed3e99e02 Mon Sep 17 00:00:00 2001 From: Austen Mack-Crane Date: Wed, 4 Mar 2020 16:00:14 -0500 Subject: [PATCH 2/2] Fixed smdPlot inputs and added a 'select all' button added req() lines to prevent errors before input fields are set --- shinyapp/app.R | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/shinyapp/app.R b/shinyapp/app.R index f1c4e6d..106d367 100644 --- a/shinyapp/app.R +++ b/shinyapp/app.R @@ -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", @@ -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 @@ -63,12 +65,14 @@ 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({ @@ -76,29 +80,39 @@ server <- function(input, output,session) { 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()) })