am a bit new to R. I am able to manipulate csv data in any way with in rstudio console.However,when i move the code to shinyr or shinydashboard environment, i am unable to manipulate the data apart from just reading it. Some of the errors am getting include:
Warning: Error in datatable: 'data' must be 2-dimensional (e.g. data frame or matrix)
Warning: Error in $: object of type 'closure' is not subsettable
I have tried moving the data from renderDataTable() to reactive() since there are a lot of variables with in the code whose values change quite often based on the different csv files read.I was hoping that the data conversions such as( tostring, as.date) would be able to convert well within the reactive()
function(input, output, session) {
dhh <- reactive({
inFile <- input$file
if (is.null(inFile)) return(NULL)
datatables <- read.csv(input$file[[1, 'datapath']], check.names=FALSE)
return(datatables)
})
output$terry <- renderDataTable({
if (is.null(dhh)) return(NULL)
datatables <- data.frame(dhh())
datatables
})
mk <- reactive({
if (is.null(input$file)) return(NULL)
inFile <- input$file
datatable <- read.csv(input$file[[2, 'datapath']], check.names=FALSE)
return(datatable)
})
output$contents <- renderDataTable({
if (is.null(mk)) return(NULL)
datatable <- data.frame(mk())
datatable
})
gloria <- reactive({
alice <- dhh()
calvin <- mk()
x1=calvin[order(nrow(calvin):1),] #invert row order
ppp <- as.character(alice$Client )
non <- data.frame(calvin$CLIENTID)
vcv <- c(ppp)
tttt <- as.vector(non)
r <- calvin[non %in% vcv, ]
pipo <- r %>%
mutate(UPDATED.ON=as.Date(r$UPDATED.ON, format = "%m/%d/%Y"))%>%
group_by(CLIENTID) %>%
arrange(desc(UPDATED.ON)) %>%
slice(1)
#calculate difference in days
y <- pipo$UPDATED.ON
tr <- as.Date(y, format = "%Y/%m/%d")
jp <- Sys.Date()
ty <- as.numeric(difftime(Sys.Date(), tr), units="days")
ty
})
output$marvin <- renderDataTable({
gloria()
})