I'm trying to add two new columns to a dataframe in shiny. I'm currently getting the error invalid 'envir' argument of type 'closure' but I'm not sure why.
My server.R code is :
server <- function(input, output) {
inFile <- reactive({input$file1})
data <- reactive({
if (is.null(inFile())) return(NULL)
read.xlsx2(inFile()$datapath,
1,
sheetName=NULL,
colIndex = c(1:7),
header = TRUE)
})
z_scores <- reactive({
if (is.null(inFile())) return(NULL)
with(data, ave(as.numeric(data$Raw.Score), data$Reader.Name, FUN=scale))
})
percentile <- reactive({
if (is.null(inFile())) return(NULL)
format( pnorm(data$z_scores) * 100, scientific = FALSE)
})
processedData <- reactive({
if (is.null(inFile())) return(NULL)
cbind(
data(),
z_score = z_scores(),
percentile = percentile()
)
})
output$view <- renderDataTable(
processedData(),
options = list(pageLength = 10)
)
}
my ui.R code is :
ui <- shinyUI( fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose XLSX File", accept = ".xlsx"),
checkboxInput("header", "Header", TRUE)
),
mainPanel(
dataTableOutput("view")
)
)
) )
What do I need to do to avoid this error? I'm not even sure what it's trying to tell me.
Thanks