I'm very new to R, SQL and Python and am taking courses and I've puzzled out most of this final project but I can not seem to figure out why this code isn't working out. I've gone back and forth with the staff instructors a few times and fixed some things but I just can't figure out this last bit. we're given a starting server.r document with some pre-built code and instructions on what to fill in. I've been through the UI code and checked it and that is fine and working so it seems server.r is where my issue is.
https://github.com/naysaa/IBM-project.git
I've got the following
TASK 5: Create logic to plot histogram or boxplot
output$p1 <- renderPlot({
if (input$graph_type == "histogram") {
# Histogram
ggplot(df_country(), aes_string(x = input$continuous_variable)) +
{
geom_histogram(bins = input$bins)
} + # histogram geom
labs(y = "country", title = paste("Trend of ", input$continuous_variable)) + # labels
facet_wrap(~prediction) # facet by prediction
}
else {
# Boxplot
ggplot(df_country(), aes_string(y = input$continuous_variable)) +
geom_boxplot() + # boxplot geom
coord_flip() + # flip coordinates
labs(title = paste(input$continuous_variable)) + # labels
facet_wrap(~prediction) # facet by prediction
}
})
TASK 6: Create logic to plot faceted bar chart or stacked bar chart
output$p2 <- renderPlot({
# Bar chart
p <- ggplot(df_country(), aes_string(x = factor(input$categorical_variables),
fill = factor(!!input$categorical_variables))) +
labs(x = input$categorical_variables,
title = paste("Trend of", input$categorical_variables)) + # labels
p + theme(legend.position="bottom") # modify theme to change text angle and legend position
if (input$is_stacked) {
p + geom_bar(stat = "count" ) + fill(factor(!!input$categorical_variables)) # add bar geom and use prediction as fill
}
else{
p +
ggplot(data = adult,
aes(x = factor(input$categorical_variable),
fill = factor(!!input$categorical_variable))) +
geom_bar() +
labs(x = input$categorical_variable,
title = paste(input$categorical_variable)) + # add bar geom and use input$categorical_variables as fill
facet_wrap(~prediction) # facet by prediction
}
})
})
And when I run it I get this Error
Warning: Error in : stat_bin() requires an x or y aesthetic.
184:
Warning: Error in !: invalid argument type
172: factor
168: renderPlot [/cloud/project/r shiny/server.R#43]
166: func
126: drawPlot
112: reactive:plotObj
96: drawReactive
83: renderFunc
82: output$p2
1: runApp