Search code examples
rshinyshiny-serverfrequency-analysisshiny-reactivity

Getting "table of extent 0" in Shiny Web app output


I have a data file that I read in in my Shiny server function. I would like to display a frequency table of the two columns the user selects using drop-downs. I get the error "table of extent 0". I have looked at R error - Table of extent 0 and Can't solve table issue but I have imported my data correctly and the column names match as well. The same line of code works when I run it in the console.

Here is my code:

shinyServer(function(input, output) {
  output$courseData = renderPrint( {


    data = read.csv(file = 'FourCourseTableLetterGrades_POLISHED.tsv', sep = '\t', header = TRUE)
    c1 = input$course1
    c2 = input$course2
    tbl = table(data$c1, data$c2)
    tbl

  }

  )
}

)

Update: this is what the table looks like right now:

screenshot

I would like the output to be in matrix format, just as what you get when running the table command in console. I also don't know why the columns are named Var1 and Var2 and where to change them.


Solution

  • Using data[[c1]] instead of data$c1 as suggested in the comments removed the error and showed a basic (although malformed) output. I did not understand why.