I recently asked a question about issues with reactivity in Shiny, and I modified my code due to the comments I received, but I still cannot get it to work. As I mentioned before, I know that without the reactivity, the plot works, so it's definitely a reactivity issue.
In my UI I have a selectInput with choices A, B, C, D. (Corresponding to 4 data frames A, B, C, D).
In my server:
colors <- c("red", "blue", "green", "purple")
data <- reactive({
if(input$selectInput == "A"){
A
} else if(input$selectInput == "B") {
B
} else if(input$selectInput == "C") {
C
} else if(input$selectInput == "D") {
D
}
data <- na.omit(as.data.frame(data$cover_group))
names(data) <- c("tmp")
})
group_factor <- reactive({
group_factor <- as.factor(data()$tmp)
group_factor <- fct_recode(group_factor, OTHER = "E", OTHER = "SPONGES", OTHER = "F", OTHER = "G", OTHER = "H", OTHER = "I", OTHER = "J")
})
bar <- reactive({
ggplot(data = data()) +
geom_bar(mapping = aes(x = group_factor(), y = ..count../sum(..count..)), fill = colors) + xlab("Cover Group") + ylab("Percent")
})
observe({
output$coverTypeBarChart <- renderPlot(bar())
})