Hi,
I am creating a shiny application consisting in plotting data from different datasets.
Basically user has to choose two times using one radiobutton and one selectinput for getting desired plot. This is my code for creating reactive data:
data_intacc <- reactive({
# Return the appropriate data source depending on
# the chosen radio button
if (input$ind_access == "reason_access" & input$dissag_access == "age_access") {
data <- lim_internet %>% select("Reason", "9–11", "12–14", "15–17")
} else if (input$ind_access == "reason_access" & input$dissag_access == "gender_access") {
data <- lim_internet %>% select(Reason, Male, Female)
} else if (input$ind_access == "reason_access" & input$dissag_access == "reason_access") {
data <- lim_internet %>% select(Reason, Total)
}
else if (input$ind_access == "places_access" & input$dissag_access == "age_access") {
data <- place_access %>% select("Place", "9–11", "12–14", "15–17")
} else if (input$ind_access == "places_access" & input$dissag_access == "gender_access") {
data <- place_access %>% select(Place, Male, Female)
} else if (input$ind_access == "places_access" & input$dissag_access == "reason_access") {
data <- place_access %>% select(Place, Total)
}
else if (input$ind_access == "freq_access") {
data <- device_freq}return(data)
})
I have created one function for plotting:
output$gmplot <-renderPlot({
p1 <- ggplot(data = data_intacc(), aes(x, y, fill= Total)) +geom_bar(stat= "identity") print(p1)
})
and in my ui.R I have:
plotOutput("gmplot")
My problem is that based on user input data is different, so I need to figure out one way to subset reactive data inside ggplot2 to define aes(x, y).
Any idea how to deal with this case?
Thank you