Working with a Shiny Dashboard, ui.r, server.r and several r scripts that contain functions.
Base problem is: I have two data sets that I bring into the server.r and I pass those to a function the prepares/cleanses the data sets and then binds them together and should return a complete dataframe. The dataFrame should be reactive. Here is what I have so far:
In the server.r I load the data prior to the function(input, output, session). Then I have:
################server.r code #########################
data <- reactive({
testDF <- prepData(data1, data2)
})
The prepData function does a variety of things but ends with:
####################prepData function return#################
return(rbind(data1, data2))
If I use something like:
############## server.r code#######################
value = nrow(data()),
Then the code returns the correct value. However I would prefer to just return the data frame as I did with testDF.
Shiny will throw and error in the UI of object 'testDF' not found.
I tried working through: How do I build a reactive dataframe in R / Shiny? using the code:
dataR <- prepData(data1, data2)
makeReactiveBinding(dataR)
This still throws the error. The function is clearly working and has been validated but there must be something I don't understand about the reactive component of utilizing this function. Any help would be appreciated. Thanks!
server.ui
function(input, output, session) {
### PreProcess the Data
data <- reactive({
testDF <- prepData(bdata, qdata)
})
#dataR <- prepData(bData, qData)
#makeReactiveBinding(dataR)
### Information Box Populations
output$monthlytransactions = renderInfoBox({
infoBox(
title = "Payments",
value = nrow(data()),
icon = icon("comments-dollar"),
color = "blue"
)
})
output$monthlyGrossDollars = renderInfoBox({
infoBox(
title = "Payments",
value = sum(testDF$GrossAmount),
icon = icon("comments-dollar"),
color = "blue"
)
})
}
prepData
############# FUNCTIONS ##############
prepData <- function(beamData, qlawData){
##Processing##
#Join DFs
return(rbind(bData, qData))