Hi!
I am trying to make a simple app that lets a user upload some data to be subsetted and manipulated, etc, and then download the final product. So far I have not been able to get the data to upload in a way that will allow me to manipulate it. When I upload data locally using either a file pathway or read.csv(file.choose()) everything works fine, so it is just a matter of getting the data to upload through glimmer. Any help would be appreciated! Here is a simplified version of what I am trying to do (and one version (of many) of what I have tried so far). Thanks in advance! Pardon my ignorance, I have only been fiddling with shiny for a couple of days so far.
Cheers,
Zak
ui.R
# define the sidebar
shinyUI(pageWithSidebar(
# title
headerPanel("Zak's RMBL bee label maker"),
sidebarPanel(
fileInput('file1', 'Choose CSV File',
accept=c('text/csv', 'text/comma-separated-values,text/plain')),
tags$hr(),
downloadButton('downloadData', 'Download labels')
),
mainPanel(
tableOutput('table')
)
))
server.R
# Define server logic
shinyServer(function(input, output) {
# get the data
d <- input$file1
l<-matrix(nrow=(ceiling(length(d[,1])/11))*6,ncol=11) # make the empty matrix
k<-1 # counter in the nested for loops below
# make the insect labels from uploaded raw data
for (j in ((c(1:(length(l[,1])/6))*6)-5)){
for (i in c(1:11)) {
l[j,i]<-paste(d[k,9]," USA: CO: Gunnison Co.")# bee number, county info
l[j+1,i]<-paste("RMBL,",d[k,5],d[k,6]) #site info
l[j+3,i]<-paste(d[k,2],d[1,1],", ",d[k,12]) # date and collector
l[j+4,i]<-paste(d[k,11],d[k,10])
l[j+5,i]<-paste("")
##### more guts of the insect label maker that I have omitted for the sake of simplicity in this post #####
if (k < length(d[,1])) k<-k+1
}
}
# Show the values using an HTML table
output$table <- renderTable({
l
})
# allow the data to be downloaded
output$downloadData <- downloadHandler(
filename = function() { paste("bee labels", '.csv', sep='') },
content = function(file) {
write.csv(l, file)
}
)
})
On Tuesday, March 5, 2013 5:20:00 PM UTC-5, Joe Cheng [RStudio] wrote: