I have created a reprex to test it out, if anything else needs to be added please let me know.
library(shinyjs)
library(shiny)
library(shinydashboard)
library(ggplot2)
library(dplyr)
library(plotly)
library(shinyWidgets)
tType = c("Forced Labour", "Forced Labour", "Sexual Exploitation", "Sexual Exploitation", "Sexual Exploitation", "Sexual Exploitation")
start = c("11/05/2005", "02/09/2008","5/24/2009","11/23/2011", "11/23/2011", "11/23/2011")
end = c("11/05/2005", "02/09/2008","5/24/2009","11/23/2011", "11/23/2011", "11/23/2011")
newngo = c(tType, start, end)
newngo = as.data.frame(newngo)
UI:
ui <- dashboardPage(skin = ("black"),
dashboardHeader(title = "Human Trafficking"),
dashboardSidebar(
sidebarMenu(
dateInput("start", "Start Date:", value = "2019-08-01", format = "dd-mm-yyyy",
min = "2000-01-01", max = "2019-09-04"),
dateInput("end", "End Date:", value = "2019-09-05", format = "dd-mm-yyyy",
min = "2000-01-02", max = "2019-09-05")
)
),
dashboardBody(
fluidRow(
box(width = 6, solidHeader = TRUE, status = "success",
title = "Trafficking Type",
selectInput("traffickingType", "Choose a trafficking type: ",
choices = sort(unique(newngo$tType)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
plotlyOutput("traff", width = '750px', height = '300px')
)
)
)
)
Server:
server <- function(input, output, session) {
filteredData <- reactive({
filtNgo <- newngo
if(!is.null(input$traffickingType)) {
filtNgo <- filtNgo %>% filter(tType %in% input$traffickingType)
}
filtNgo
})
output$traff <- renderPlotly({
#newngo %>% filter(start >= input$startdate, end <= input$end) %>%
plot_ly(filteredData(), labels = tType, type = "pie",
marker = list(colors = colors,
line = list(color = '#FFFFFF', width = 1))) %>%
layout(showlegend = FALSE)
})
}
shinyApp(ui, server)