I have made a reproducible example that is needed to test. 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)
vNation = c("India", "India", "India", "Myanmar", "Myanmar", "Nepali", "Nepali", "Nepali", "Nepali", "United Kingdom", "Oman")
newngo = vNation
newngo = as.data.frame(newngo)
UI:
ui <- dashboardPage(skin = ("black"),
dashboardHeader(title = "Human Trafficking"),
dashboardSidebar(
sidebarMenu(
)
),
dashboardBody(
fluidRow(
infoBoxOutput("progressBox", width = 6)
),
fluidRow(
box(width = 6, solidHeader = TRUE, status = "primary",
title = "Victim Nationality",
selectInput("vicNation", "Select victim nationality: ",
choices = sort(unique(vNation)), selected = NULL,
multiple = TRUE, selectize = TRUE, width = NULL, size = NULL),
plotlyOutput("Nationality", width = '750px', height = '300px')
)
)
)
)
Server:
server <- function(input, output, session) {
filteredData <- reactive({
filtNgo <- newngo
if(!is.null(input$vicNation)) {
filtNgo <- filtNgo %>% filter(vNation %in% input$vicNation)
}
filtNgo
})
output$Nationality <- renderPlotly({
plot_ly(filteredData(), labels = vNation, type = "pie",
marker = list(colors = colors,
line = list(color = '#FFFFFF', width = 1))) %>%
layout(showlegend = FALSE)
})
output$progressBox <- renderInfoBox({
infoBox(
input$vicNation,
value = paste("Total", nrow(newngo %>% filter(vNation == input$vicNation)),
collapse = " "),
icon = icon("user-friends"),
color = "black",
fill = T
)
})
}
shinyApp(ui, server)
Currently if the user selects one country it states the name and how often it occurs. What I am looking for is if the user selects multiple options it will state both e.g. United Kingdom, India and then add the total of the two. Thanks
Updated to better reproducible example