title: R Shiny Error: Warning: Error in $: object of type 'closure' is not subsettable
body: <p>I am using the following code and I always get this subsettable error unless if I run the line</p>
  <p><code>df &lt;- read.csv(&quot;./world-happiness-report-cleaned.csv&quot;)</code>
  manually before running the app. What am I subsetting, and where am I wrong? I can't seem to find the error, and I'm super new to Shiny so I've never had to deal with this before. Thank you so much!!</p>
  <p>This link is to a filebin that has the csv I used: <a href="https://filebin.net/wjctohctz1sxm16y" rel="nofollow noreferrer">https://filebin.net/wjctohctz1sxm16y</a></p>
  <p>server.R</p>
  <pre><code># Elit Jasmine Dogu, ejd5mm
  # Project One DS 3002
  library(dplyr)
  library(countrycode)
  library(shiny)
  df &lt;- read.csv(&quot;./world-happiness-report-cleaned.csv&quot;)
  
      #saveRDS(df, &quot;./df.RDS&quot;)
  server &lt;- function(input, output) {
      #reading in the data and basic data cleaning 
      #df&lt;- read.csv(&quot;world-happiness-report-cleaned.csv&quot;)
      #df &lt;&lt;- readRDS(&quot;./df.RDS&quot;)
      #df &lt;- read.csv(&quot;./world-happiness-report-cleaned.csv&quot;)
      
      # Filter data based on user selections
      output$table &lt;- DT::renderDataTable(DT::datatable({
          data &lt;- df %&gt;%
              filter(
                  if(input$year != &quot;All&quot;) {
                      Year ==input$year
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$country != &quot;All&quot;) {
                      Country ==input$country
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$continent != &quot;All&quot;) {
                      Continent ==input$continent
                  } else {TRUE}
              )
          
          return(data)
          
      }))
          # Generate a summary of the dataset (on the left panel)
          output$summary &lt;- renderPrint({
              data &lt;- df %&gt;%
                  filter(
                      if(input$year != &quot;All&quot;) {
                          Year ==input$year
                      } else {TRUE}
                  ) %&gt;%
                  filter(
                      if(input$country != &quot;All&quot;) {
                          Country ==input$country
                      } else {TRUE}
                  ) %&gt;%
                  filter(
                      if(input$continent != &quot;All&quot;) {
                          Continent ==input$continent
                      } else {TRUE}
                  )
              
              return(summary(data))
              
          })
      
         #Generate a function to show the number of rows w/ any given dataframe selection/restriction
      rows = function() {
          data &lt;- df %&gt;%
              filter(
                  if(input$year != &quot;All&quot;) {
                      Year ==input$year
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$country != &quot;All&quot;) {
                      Country ==input$country
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$continent != &quot;All&quot;) {
                      Continent ==input$continent
                  } else {TRUE}
              )
          
          return(nrow(data)) #returns number of rows of the data
      }
      
      #Generate a function to show the number of columns w/ any given dataframe selection/restriction
      cols = function() {
          data &lt;- df %&gt;%
              filter(
                  if(input$year != &quot;All&quot;) {
                      Year ==input$year
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$country != &quot;All&quot;) {
                      Country ==input$country
                  } else {TRUE}
              ) %&gt;%
              filter(
                  if(input$continent != &quot;All&quot;) {
                      Continent ==input$continent
                  } else {TRUE}
              )
          
          return(ncol(data)) #returns the number of columns of the data
      }
  
      #Using the functions created above
          output$columns  &lt;- renderText({
              paste(&quot;Number of Columns:&quot; , cols() ) #text to display the number of columns
          })
          output$rows  &lt;- renderText({
              paste(&quot;Number of Rows (Records):&quot; , rows() ) #text to display the number of rows 
          })
  
          output$data_ex  &lt;- renderText({
              paste(&quot;Please see README.md file for information regarding the dataset.&quot;) #text to display where to find more information
          })
   
  
          # Downloadable csv of selected dataset 
          output$downloadData &lt;- downloadHandler(
              filename = function() {
                  selected &lt;-c() #this assists with the name of the file
                  if (input$year != &quot;All&quot;) { 
                      selected &lt;-c(selected, input$year)
                  }
                  if (input$country != &quot;All&quot;) {
                      selected &lt;-c(selected, input$country)
                  }
                  if (input$continent != &quot;All&quot;) {
                      selected &lt;-c(selected, input$continent)
                  }
                  if (length(selected) == 0) {
                      selected &lt;- c(&quot;AllData&quot;)
                  }
                  
                  paste0(paste(selected, collapse=&quot;-&quot;), &quot;.csv&quot;)
              },
              content = function(con) {
                  data &lt;- df %&gt;%
                      filter(
                          if(input$year != &quot;All&quot;) {
                              Year ==input$year
                          } else {TRUE}
                      ) %&gt;%
                      filter(
                          if(input$country != &quot;All&quot;) {
                              Country ==input$country
                          } else {TRUE}
                      ) %&gt;%
                      filter(
                          if(input$continent != &quot;All&quot;) {
                              Continent ==input$continent
                          } else {TRUE}
                      )
                  write.csv(data, con, row.names = TRUE) #saves the filtered data
              }
          )
  }
  
  </code></pre>
  <p>ui.R</p>
  <pre><code># Elit Jasmine Dogu, ejd5mm
  # Project One DS 3002
  library(shiny)
  library(shinyWidgets)
  
  ui &lt;- fluidPage(
      #text with project name and my information
      titlePanel(&quot;World Happiness Report&quot;),
      tags$h3(&quot;DS 3002- Project One&quot;),
      tags$h4(&quot;Elit Dogu, ejd5mm 3rd Year UVA&quot;),
      # use a gradient in background, setting background color to blue
      setBackgroundColor(  
          #https://rdrr.io/cran/shinyWidgets/man/setBackgroundColor.html used this website for help on background color
          color = c(&quot;#F7FBFF&quot;, &quot;#2171B5&quot;),
          gradient = &quot;radial&quot;,
          direction = c(&quot;top&quot;, &quot;left&quot;)
      ),
      # Sidebar layout with input and output definitions ----
      sidebarLayout(
          
          # Sidebar panel for inputs ----
          sidebarPanel(
              
              # Output: Header + summary of distribution ----
              h4(&quot;Summary&quot;),
              verbatimTextOutput(&quot;summary&quot;),
              
              # Download button
              downloadButton(&quot;downloadData&quot;, &quot;Download&quot;)
          ),
      # Create a new Row in the UI for selectInputs
      # Main panel for displaying outputs ----
      mainPanel(
  
      fluidRow(  #manipulates the original dataframe given user selection
          column(4,
                 selectInput(&quot;year&quot;,  #selection for the year variable
                             &quot;Year:&quot;,
                             c(&quot;All&quot;,
                               unique(as.numeric(df$Year))))
          ),
          column(4,
                 selectInput(&quot;country&quot;,  #selection for the country variable
                             &quot;Country:&quot;,
                             c(&quot;All&quot;,
                               unique(as.character(df$Country))))
          ),
          column(4,
                 selectInput(&quot;continent&quot;,  #selection for the continent variable
                             &quot;Continent:&quot;,
                             c(&quot;All&quot;,
                               unique(as.character(df$Continent))))
          )
      ),
      # Create a new row for the table
      DT::dataTableOutput(&quot;table&quot;),
      
      # Create a new column for the text to be displayed
      column(12,
             verbatimTextOutput(&quot;columns&quot;) #column to display col count
      ),
      column(12,
             verbatimTextOutput(&quot;rows&quot;) #column to display row count
      ),
  
      column(12,
             verbatimTextOutput(&quot;data_ex&quot;) #column to display more information text
              )
          )
      )
  )
  </code></pre>
  <p>Thank you!!</p>