I have a database consisting of
- Code of middle schools (code)
- Gender of the students (Cod_Sexe)
- Decision Concerning the student; A: Pass , R:Fail (Decision)
- Behaviour of the student during the year ; 0: Bad , 1:Good (Conduite).
This data is divided over 3 years: 2008,2011 and 2014. I am using R shiny, I created graphs for gender, decision and behaviour and just display the number of middle schools and students. Now I want to enable the user to filter this data according to a certain year. Here's the code:
USER INTERFACE
ui <- fluidPage(
textOutput("inst_nbr"),
textOutput("stunbr"),
plotOutput("plot_decision"),
plotOutput("genderdonut"),
plotOutput("Conduite"),
checkboxGroupInput(inputId = "YearSelect", "Select the corresponding year",
choices = levels(factor(Test2008$Year)), selected = levels(factor(Test2008$Year)))
)
inst_nbr : middle school number / stunbr: students number / plot_decision: histogram of the decisions(A/R) / genderdonut:donut chart for the gender distribution / Conduite:donut chart for the behavior / YearSelect: filter created from the database
Server
# CREATE YEAR FILTER
TestFilter <- reactive({ # <-- Reactive function here
Test2008 %>%
filter(Test2008$Year == input$YearSelect)
})
# NBR OF INSTITUTIONS
output$inst_nbr= renderText({
Test=TestFilter()
length(unique(x = Test$Code))
})
# PLOT DECISION DIAGRAM
# % of each decison
Per_A= 100*length(which(Test2008$Decision=='A'))/length(Test2008$Decision)
Per_R= 100*length(which(Test2008$Decision=='R'))/length(Test2008$Decision)
DecisionName=c('Accepté','Refusé')
DecisionFraction=c(Per_A,Per_R)
# Plot of decisions
output$plot_decision=renderPlot({
Test=TestFilter()
barplot(height= DecisionFraction, names = DecisionName )
})
I applied the filter to the number of middle school, however I don't know how to apply it to the graph.