R Studio Help w/ Shiny

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?


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:",
  selectInput("Y", "Y Variable:",

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)]
           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"),

shinyApp(ui = ui, server = server)

You have unnecessarliy complicated a presumably simple correlation plotting code.
BTW what are these lines supposed to do?

 x_column <- selections()[,6]
 y_column <- selections()[,4]

I guess you have only two columns in selections() data.frame.

I believe they select the current variables in the dataset of (mtcars).

But it has only 2 columns, isnt it?

selections <- reactive({
    aq.no.missing[, c(input$X, input$y)]

Yes only two columns

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.