title: R Shiny read csv file
body: <p>If I may, I have another question about reading a csv file while using Shiny.</p>
  
  <p>I did spend quite a bit of time searching and rtfm ... my apologies if I missed something.  Most answers seemed a bit too fancy, with user interaction when selecting a data file.  I simply want R Shiny to read a data file (just the one) without any user interaction.</p>
  
  <p>I have the standard files ui.R and server.R
  I place them in a working directory.</p>
  
  <p>I have a csv file with data which I place in a subdirectory called 'data' (based on a tutorial here <a href="http://shiny.rstudio.com/tutorial/lesson5/" rel="noreferrer">http://shiny.rstudio.com/tutorial/lesson5/</a>)</p>
  
  <p>From within R Studio I manually set the working directory to the one with the ui.R and server.R files.
  I load shiny and do runApp(). 
  A line of script in server.R tries to use read.csv to read the data into an object 'd.in'.</p>
  
  <p>This did not work, so I tried coercing the working directory before reading the csv file, and then resetting it after reading the data and before the shinyServer code.</p>
  
  <p>code snippet:</p>
  
  <pre><code>wd.datapath = paste0(getwd(),"/data")
  wd.init = getwd()
  setwd(wd.datapath)
  
  d.in = read.csv("shinyDataITB.csv", header = TRUE)
  
  setwd(wd.init)
  </code></pre>
  
  <p>I get an error message: "ERROR: object 'd.in' not found"</p>
  
  <p>If I manually load the csv data file prior to running runApp then everything else seems to work.  I'm not sure how I've botched this but any help will be welcome.</p>
  
  <p>The ui.R file</p>
  
  <pre><code>##### ui.R #####
  
  library(shiny)
  
  shinyUI(pageWithSidebar(
  
    headerPanel("Supply ITB"), 
  
    sidebarPanel( 
  
      radioButtons(inputId = "in.facnum",
                   label = "Choose Facility",
                   choices = levels(d.in$facnum)) 
      ),  # end sidebarPanel
  
    mainPanel(
      h3("SPC chart"), 
      plotOutput("plotDisplay")
      )   # end mainPanel
  
    ))    # end Sidebar
  </code></pre>
  
  <p>And the server.R file</p>
  
  <pre><code>##### server.R #####
  
  # load packages -------------------------------------------------------------
  
  library(shiny)
  library(qcc)
  
  # load the data -------------------------------------------------------------
  
  
  wd.datapath = paste0(getwd(),"/data")
  wd.init = getwd()
  setwd(wd.datapath)
  
  #d.in = read.csv(file.choose(), header = TRUE)
  
  d.in = read.csv("shinyDataITB.csv", header = TRUE)
  
  setwd(wd.init)
  
  
  # add proportions related to fill_lines -------------------------------------
  
  d.in$whprop = d.in$wh / d.in$volume
  d.in$dmprop = d.in$dm / d.in$volume
  d.in$mmprop = d.in$mm / d.in$volume
  
  
  # select SPC response variable (using proportions) --------------------------
  
  qccvar = "whprop"
  
  
  # shiny server body ---------------------------------------------------------
  
  shinyServer(function(input,output) { 
  
  
  # Individuals (X) chart -----------------------------------------------------
  
    output$plotDisplay &lt;- renderPlot({
  
      # select subset for specific facility
  
      d.strata = subset(d.in, d.in$facnum == input$in.facnum)  # subset
  
      d.strata = d.strata[order(d.strata$year, d.strata$monthnum, 
                                decreasing = FALSE),]  # order by month
  
      # create SPC chart
  
      x.chart = qcc( d.strata[,qccvar], type = "xbar.one", 
                 title = paste("Individuals chart\n", input$in.facnum, qccvar) )
  
  
    })  # end renderPlot
  
  })    # end shinyServer
  
  
  ### END CODE ###
  </code></pre>
  
  <p>I've put the data file in a dropbox folder here <a href="http://goo.gl/xgu1Qc" rel="noreferrer">shinyDataITB.csv</a></p>