title: RStudio Shiny Error - number of items to replace is not a multiple of replacement length
body: <p>I am fairly new to R and currently working on a Shiny web app using RStuido to recognise handwritten digits. </p>
  
  <p>The data I am using is from a Kaggle competition:
  <a href="https://www.kaggle.com/c/digit-recognizer/data" rel="nofollow">Digit-Recogniser</a></p>
  
  <p>I have the following function to render average representations of digits</p>
  
  <pre><code> # Produce a plot containing the average representations of digits
  
    output$digitAvgRep &lt;- renderImage({
  
      ## For visualising traing data
      dataFrame&lt;-as.matrix(data())
  
      ##Color ramp def.
      colors&lt;-c('white','red')
      cus_col&lt;-colorRampPalette(colors=colors)
  
      ## Plot the average image of each digit
      par(mfrow=c(4,3),pty='s',mar=c(1,1,1,1),xaxt='n',yaxt='n')
      all_img&lt;-array(dim=c(10,28*28))
      for(di in 0:9)
      {
        print(di)
        all_img[di+1,]&lt;-apply(dataFrame[dataFrame[,1]==di,-1],2,sum)
        all_img[di+1,]&lt;-all_img[di+1,]/max(all_img[di+1,])*255
  
        z&lt;-array(all_img[di+1,],dim=c(28,28))
        z&lt;-z[,28:1] ##right side up1
        image(1:28,1:28,z,main=di,col=cus_col(256))
      }
    })
  </code></pre>
  
  <p>and I pass the above variable to ui.R using:</p>
  
  <pre><code># User renderUI to dynamically create objects in the ui.R 
    output$tb &lt;- renderUI({
      if(is.null(data()))
        h5("No data loaded.")
      else
        tabsetPanel(
          tabPanel("About file", tableOutput("filedf")),
          tabPanel("RawData", tableOutput("table")),
          tabPanel("Summary", tableOutput("sum")),
          tabPanel("Digit Distribution",plotOutput("digitDist")),
          tabPanel("Average Digit Representation", imageOutput("digitAvgRep")))
    })
  </code></pre>
  
  <p>I get the following output when I run the app:</p>
  
  <pre><code>[1] 0
  Error in all_img[di + 1, ] &lt;- apply(dataFrame[dataFrame[, 1] == di, -1],  : 
    number of items to replace is not a multiple of replacement length
  </code></pre>
  
  <p>Anyone know how to solve this?</p>
  
  <p>Thanks</p>