How do you use the filtered output from datatables in further functions? I am making a Shiny app where the data is uploaded and filtered by the user with a datatable. I then want to use the filtered data to perform some functions. I give one below (calcs()). I am getting the Error: invalid 'x' type in 'x && y'.
The .csv file is:
Day: 1,2,3
Subject: 1,2,3
Location: 1,1,2
ui.R
shinyUI(fluidPage(theme = shinytheme("spacelab"),
# title and subtitles
titlePanel(
h1(HTML("</b>Test App</b>"),
style="text-align:center")),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose Input .csv File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
downloadButton("downloadData",
"Download Results (.xlsx)")
),
mainPanel(title = "Raw Data",
DT::dataTableOutput("table"),
)
)
))
server.R
shinyServer <- function(input, output, session) {
datasetInput <- reactive({
if(is.null(input$file1)) return(NULL)
csv_data <- read.csv(input$file1$datapath)
})
output$table = DT::renderDataTable(datasetInput(),
filter = "top",
server = "FALSE")
calcs <- reactive({
remove_pos_baseline <- as.data.frame(input$table_rows_all) %>%
group_by(Location) %>%
mutate(count = first(Subject))
})
data_list <- reactive({
list(
table = calcs(),
patient_results = datasetInput()
)
})
output$downloadData <- downloadHandler(
filename = function() {
paste("Output", datasetInput()$Location[1], "-", Sys.Date(), ".xlsx", sep="")
},
content = function(file) {
write_xlsx(data_list(), path = file)
}
)
}