I have created multiple selectInputs that will alter multiple graphs when something from the drop down menu has been selected. Currently only 3 out of the 5 graphs are working even though they all have the same code.
UI:
ui <- dashboardPage(
dashboardHeader(title = "Human Trafficking"),
dashboardSidebar(
sidebarMenu(
selectInput("Source", "Choose a Data Source: ", choices = sort(unique(newNgo$Data.Source)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
selectInput("Nationality", "Select a nation: ", choices = " "),
dateInput("startdate", "Start Date:", value = "2019-08-01", format = "dd-mm-yyyy",
min = "2000-01-01", max = "2019-09-04"),
dateInput("enddate", "End Date:", value = "2019-09-05", format = "dd-mm-yyyy",
min = "2000-01-02", max = "2019-09-05")
#actionButton("button1", "Apply"),
#actionButton("reset_input", "Reset inputs")
)
),
fluidRow(
box(width = 6, solidHeader = TRUE, status = "primary",
title = "Trafficking Type",
selectInput("traffickingType", "Choose a trafficking type: ",
choices = sort(unique(newNgo$Trafficking.Type)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
#actionButton("button2", "Apply"),
plotlyOutput("coolplot", width = '750px', height = '300px')
),
box(width = 6, solidHeader = TRUE, status = "primary",
title = "Trafficking Sub-Type",
selectInput("traffickingSubType", "Choose a trafficking sub type: ",
choices = sort(unique(newNgo$Trafficking.Sub.Type)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
#actionButton("button3", "Apply"),
plotlyOutput("Sub", width = '750px', height = '300px')
)
),
fluidRow(
box(width = 4, solidHeader = TRUE, status = "primary",
title = "Victim Gender",
selectInput("victimGender", "Choose a gender: ",
choices = sort(unique(newNgo$Victim.Gender)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
#actionButton("button4", "Apply"),
plotlyOutput("gender", width = '250px', height = '200px')
),
box(width = 4, solidHeader = TRUE, status = "primary",
title = "Transport Method",
selectInput("transp", "Choose a transportation method: ",
choices = sort(unique(newNgo$Transportation.Method)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
#actionButton("button4", "Apply"),
plotlyOutput("transportMethod", width = '250px', height = '200px')
),
box(width = 4, solidHeader = TRUE, status = "primary",
title = "Control Method",
selectInput("control", "Choose a control method: ",
choices = sort(unique(newNgo$Control.Method)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
#actionButton("button4", "Apply"),
plotlyOutput("controlMethod", width = '250px', height = '200px')
)
Server:
output$coolplot <- renderPlotly({
req(input$Nationality)
if(!is.null(input$Nationality)) {
newNgo <- newNgo %>% filter(Victim.Nationality %in% input$Nationality)
}
if(!is.null(input$gender)) {
newNgo <- newNgo %>% filter(Victim.Gender %in% input$gender)
}
if(!is.null(input$traffickingType)) {
newNgo <- newNgo %>% filter(Trafficking.Type %in% input$traffickingType)
}
if(!is.null(input$traffickingSubType)) {
newNgo <- newNgo %>% filter(Trafficking.Sub.Type %in% input$traffickingSubType)
}
if(!is.null(input$Source)) {
newNgo <- newNgo %>% filter(Data.Source %in% input$Source)
}
plot_ly(newNgo, labels = ~Trafficking.Type, type = "pie") %>%
layout(showlegend = FALSE)
})
output$control <- renderPlotly({
req(input$Nationality)
if(!is.null(input$Nationality)) {
newNgo <- newNgo %>% filter(Victim.Nationality %in% input$Nationality)
}
if(!is.null(input$gender)) {
newNgo <- newNgo %>% filter(Victim.Gender %in% input$gender)
}
if(!is.null(input$traffickingType)) {
newNgo <- newNgo %>% filter(Trafficking.Type %in% input$traffickingType)
}
if(!is.null(input$traffickingSubType)) {
newNgo <- newNgo %>% filter(Trafficking.Sub.Type %in% input$traffickingSubType)
}
if(!is.null(input$Source)) {
newNgo <- newNgo %>% filter(Data.Source %in% input$Source)
}
plot_ly(newNgo, labels = ~Control.Method, type = "pie") %>%
layout(showlegend = FALSE)
})
I have attached the code from the server with one graph that works and one that doesn't work. I also attached all the different inputs I have from the UI.