I am trying to build a file processor, where I can upload the raw file, click the button, and get the sorted report. So in this instance, I m wanting to see domain performance for different lines, so it splits the data set and writes to a .xlsx file, where the data splits for each tab based on the line.
It runs fine on RStudio, but when I publish it, I get the following errors. Either of the 2 :
error in [[ subscript out of bounds no-stack-trace-available
warning-error-in-if-argument-is-of-length-zero-no-stack-trace-available
library(openxlsx)
library(readxl)
library(writexl)
library(dplyr)
library(magrittr)
library(lubridate)
library(shiny)
ui <- fluidPage(
titlePanel("Domain Performance"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Upload file',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv','.xlsx'))
),
mainPanel(
#actionButton(inputId = "run",label = "Run the Code"),
downloadButton('sortspend',"Spend"),
tableOutput("outdata1")
)
))
server <- function(input, output) {
options(shiny.maxRequestSize=90*1024^2)
output$outdata1 <- renderTable({
req(input$file1)
if(is.null(input$file1)) {
return()
}
else {
input$file1
}
})
spenddom <-reactive({
req(input$file1)
dspec <- input$file1
domain_raw <- read.csv(dspec$datapath,header = TRUE)
linenames = unique(domain_raw['Line'])
lineids = unique(domain_raw$`Line Id`)
for (i in seq_along(lineids)){
ddf <-domain_raw%>% select(`Line Id`,Domain,`Advertiser Spending`,Impressions,Clicks,Conversion,Line)%>%
filter(`Line Id` == lineids[i])%>%
group_by(Line,Domain)%>%
summarise(Spend = sum(`Advertiser Spending`), Imp = sum(Impressions), Clicks = sum(Clicks), Conversions = sum(Conversion))%>%
mutate(CPA = Spend/Conversions)%>%arrange(desc(Spend))
}
})
tabcreator <- reactive({
req(input$file1)
dspec <- input$file1
domain_raw <- read.csv(dspec$datapath,header = TRUE)
linenames = unique(domain_raw['Line'])
lineids = unique(domain_raw$`Line Id`)
for (i in seq_along(lineids)){
tabname <- lineids[i]
}
})
output$sortspend<-downloadHandler(
filename = function(){paste0("domainperfdl",".xlsx")},
content = function(fname){
write.xlsx(spenddom(),fname,sheetName = tabcreator())
},
contentType = "application/xlsx"
)
}
shinyApp(ui=ui, server=server)
I m trying to understand what am I doing wrong here. It's the first time I m using for loops with R.