I have produced an app that allows the user to upload multiple csv files.
These csvs then 'rbind' together, 'read.csv' and have a column added to the df which is the filename.
The df is then processed to produce various plots which are downloadable. This works perfectly. However when I try download a specific data frame from within the reactive element I can't get it to work.
In this example I want to download df1 from within the testinput reactive function.
UI:
dashboardPage( skin = "black",
dashboardHeader(title = "myApp"),
dashboardSidebar(collapsed = TRUE,
sidebarMenu(
menuItem("Home", tabName = "dashboard1", icon = icon("home", lib =
"glyphicon"))
)
),
dashboardBody(
tags$head(tags$style(HTML('
.main-header .logo {
font-family: "Times New Roman", serif;
font-weight: bold;
font-size: 24px;
}
'))),
tabItems(
tabItem(tabName = "dashboard1",
fileInput("file1",
label="Input files:",
multiple = TRUE),
downloadButton('downloadData', 'Download Data')
)
)
)
)
Server:
library(shiny)
library(shinydashboard)
#server start
function(input, output) {
testinput<- reactive({
if(is.null(input$file1))
return ()
else
{
nfiles = nrow(input$file1)
csv = list()
for (i in 1 : nfiles)
{
csv[[i]] = read.csv(input$file1$datapath[i])
}
csv_names <- input$file1[['name']]
actual_names<-input$statics$name
df1<-cbind(actual_names, csv_names)
mydata <- do.call(rbind, lapply(csv_names, function(x) cbind(read.csv(x), name=strsplit(x,'\\.')[[1]][1])))
df1<-cbind(df1, mydata)
}
})
output$downloadData <- downloadHandler(
filename = function() { paste(input$downloadData, " ",Sys.Date(),".csv",sep="") },
content = function(file) {
write.csv(df1,file)
}
)
)
}
Any help would be great as I have searched lots of SO and other forums and I'm pretty stuck.