Hello! I keep getting a few errors for my code and was wondering if someone could help me? The errors I'm receiving are "Incorrect number of dimensions" and sometimes "no stack trace available". My code is below, can someone please help?
library(datasets)
library(shiny)
library(tidyr)
library(tibble)
aq.no.missing <-drop_na(mtcars)
options <- c("mpg" = "mpg",
"disp" = "disp",
"hp" = "hp",
"drat" = "drat",
"wt" = "wt",
"qsec" = "qsec")
df.options <- data.frame(options)
df.lv <- rownames_to_column(df.options)
colnames(df.lv) <- c("label","value")
ui <- fluidPage(
selectInput("X", "X Variable:",
options),
selectInput("Y", "Y Variable:",
options),
plotOutput("scatter")
)
server <- function(input, output) {
selections <- reactive({
aq.no.missing[, c(input$X, input$y)]
})
output$scatter <- renderPlot({
x_column <- selections()[,6]
y_column <- selections()[,4]
correlation <-cor(x_column,y_column)
regression <-lm(y_column-x_column)
intercept <- regression$coefficients[6]
slope <- regression$coefficients[4]
X_label <- df.lv$label[which(df.lv$value == input$X)]
Y_label <- df.lv$label[which(df.lv$value == input$Y)]
plot(x=x_column,y=y_column,xlab=X_label,ylab=Y_label,
cex.axis = 1.5,cex.lab = 1.5, pch = 20, cex = 2,
main = paste(Y_label, "vs", X_label,
"\n r =",round(correlation,3),"
Y' =",round(intercept,3),"+",round(slope,3),"X"),
cex.main=1.8)
abline(intercept,slope)
})
}
shinyApp(ui = ui, server = server)