object of type "closure" error when publishing to shinyapps.io

Hello,

I am currently working on a shiny dashboard that runs perfectly locally but returns the following error when I attempt to publish it:

Error in value[[3L]](cond) : object of type 'closure' is not subsettable

I've poked around and understand that the error stems from trying to treat a function like a data frame, but I don't think I do so anywhere in the code. As an example, my UI looks generally like:

ui <- dashboardPage(
    dashboardHeader(title = "Dashboard", titleWidth = 350),
    dashboardSidebar(
        sidebarMenu(
            menuItem("Pitchers", tabName = "Pitchers", icon = icon("baseball-ball")),
            menuItem("Hitters", tabName = "Hitters", icon = icon("male"))
        )
    ),
    dashboardBody(
        tabItems(
            tabItem(tabName = "Pitchers",
                selectInput("dataset", label = "Pitcher", choices = df$Pitcher, selected = df$Pitcher["Lamon, Owen"])
fluidRow(  
                box(title = "Velocity by Pitch Number", plotOutput("VeloPlot"), collapsible = TRUE, solidHeader = TRUE, status = "primary", width = 12)),

and in my Server code I read a csv, store it as a data frame, and refer to the inputs using "render". I commented the read.csv line per some suggestions I found online:

server <- function(input, output, session){
  #/df <- read.csv("R/Master.csv", stringsAsFactors=FALSE, sep=",", header=TRUE)
  df <- transform(df, Velocity = cut(RelSpeed, 5))
  df <- df %>% mutate(
    Chase = if_else(((PlateLocSide < -.95 | PlateLocSide > .95 | PlateLocHeight < 1.6 | PlateLocHeight > 3.5) & (PitchCall == "StrikeSwinging" | PitchCall == "FoulBall" | PitchCall == "InPlay")), 'Yes', 'No' ),
    HitHard = if_else(ExitSpeed > 90, 'Yes', 'No'),
    InZone = if_else(PlateLocSide < .95 & PlateLocSide > -.95 & PlateLocHeight > 1.6 & PlateLocHeight < 3.5, 'Yes', 'No'))
  df <- df %>%
    mutate(
      TiltHMS = hms(Tilt),
      TiltHours = (hour(TiltHMS) + minute(TiltHMS)/60)
    ) 
    output$VeloPlot <- renderPlot({
       df %>% filter(Pitcher == input$dataset) %>% ggplot() + geom_line(aes(x = PitchNo, y = RelSpeed, color = TaggedPitchType)) + xlab("Pitch Number") + ylab("Velocity") + ggtitle("Velocities by Pitch Number")
    })

Any guidance would be greatly appreciated!

df is the density function of the F distribution. Removing the line that assigns the result of read.csv to df could lead to this error. You probably had the error before you commented that line, so I am not sure that is the only problem. I suggest you replace all of your df with DF and then try to trace the problem if it still exists.

I changed the name of the data frame, and am now getting an object not found error message. I have tried reading in the csv and declaring the data frame outside of ui and server, inside of both, and inside and outside (although redundant). Am I declaring it incorrectly?

If you do not need to make the reading of the csv vary depending on user input, I would read it at the top of the app, outside of either the ui or the server. Try the simplest possible app to see if you can just read and display the csv. Here is what I tried on my system. You should be able to adjust the path and file of the read.csv() and have it work for you.

library(shiny)
DF <- read.csv("B.csv")

ui <- pageWithSidebar(
  headerPanel("My First Shiny App"),
  
  sidebarPanel( 
   
  ),     
  mainPanel(
    tableOutput("Table1")
  )
)

server <- function(input, output, session){
    output$Table1 <-renderTable({
    DF
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

I can get this to publish, but the data doesn't display, showing 'An error has occurred. Check your logs or contact the app author for clarification.' I had tried reading the csv outside of both ui and the server in my app, and the only functional difference between my app and your simpler one is that I call on one of the columns of the csv for a 'selectInput' in the ui block. Might that be what is producing the error?

I am not sure if you got my bare bones app to run or not. If that is where you the An error has occurred message, you need to find out what that error is. Unfortunately, you seem to be running on shinyapps.io and I am not familiar with that.

Please show the simplest code that you have tried to run. If I see a problem with it, I will respond but if all we have is An error has occurred, it is hard to know where to look.

It's now published with the read.csv outside both chunks and uploading the csv with the app.R in the same subdirectory. Some of the plot elements are being a little finicky, but I expect to be able to iron those out. Thank you for all the help!