Here is a sample of the data.
| Victim Nationality |
Victim Age |
Trafficking Type |
| US |
22 |
Child Labour |
| US |
28 |
Child Labour |
| US |
26 |
Domestic Servitude |
| United Kingdom |
18 |
Child Labour |
| Spain |
30 |
Labour Exploitation |
| US |
33 |
Domestic Servitude |
| Spain |
19 |
Labour Exploitation |
| United Kingdom |
20 |
Domestic Servitude |
| Czech Republic |
34 |
Labour Exploitation |
| Czech Republic |
27 |
Domestic Servitude |
| Czech Republic |
34 |
Domestic Servitude |
| US |
22 |
Child Labour |
| United Kingdom |
18 |
Child Labour |
In this case the text would read out people from US who are 22 are more susceptible to Child Labour etc.
UI
dashboardBody(
column(
wellPanel(width = 6, solidHeader = TRUE, status = "primary",
selectInput("Nationality", "Choose victim nationality: ", choices = " "),
radioButtons("genderInput", "Choose Gender: ",
list("Female", "Male", "Other", "Unknown")
)
),
width= 4,
wellPanel(width = 6, solidHeader = TRUE,
textOutput("selected_var")
)
),
box(width = 8, solidHeader = TRUE, status = "primary",
mainPanel(
plotlyOutput("coolplot", width = '900px', height = '600px')
)
)
)
Server
traffickerNationalities = sort(unique(ngo$Trafficker.Nationality))
updateSelectInput(session, "TraffickerNation", choices = traffickerNationalities)
nationalities = sort(unique(ngo$Victim.Nationality))
updateSelectInput(session, "Nationality", choices = nationalities)
output$selected_var <- renderText({
paste(input$genderInput, " from ", input$Nationality, " are more susceptible to ")
})
output$coolplot <- renderPlotly({
ngo <-
ngo %>%
filter(Victim.Nationality == input$Nationality,
Victim.Gender == input$genderInput
)
p = ggplot(ngo, aes(x = Victim.Age, fill = Trafficking.Type)) +
geom_bar(position = "stack")
ggplotly(p) %>%
layout(showlegend = FALSE)
})