I am working on a shiny app that takes a user uploaded Excel file, performs some common data manipulations on it, and produces tables and graphs for the user. I would like the tables/graphs to be tied to filters so the user can dynamically filter based on the contents of a few columns. Right now, I get stuck in an endless loop of a warning that says "Warning: Error in UseMethod: no applicable method for 'select' applied to an object of class "NULL"". Code is below.
app.r
# Load Libraries
## Data Manipulation
library(DT)
library(data.table)
library(readxl)
library(tidyverse)
## Shiny
library(shiny)
library(shinybusy)
library(shinyWidgets)
library(shinydashboard)
# Custom funtion
`%nlike%` <- Negate(`%like%`)
# Define UI for the application
ui <- dashboardPage(
dashboardHeader(title = "Assay Metrics"),
dashboardSidebar(
fileInput("file", "Data", buttonLabel = "Upload..."),
sidebarMenu(menuItem(
"Validated",
tabName = "validated",
icon = icon("ok", lib = "glyphicon")
))
),
dashboardBody(tabItems(tabItem(
tabName = "validated",
tabPanel("Validated",
fluidRow(
tabBox(
width = 12,
title = "Validated Data",
id = "validated",
tabPanel(
"Validated Summary Chart and Graphs",
selectizeGroupUI(
id = "validated_data_summary_filters-filters",
params = list(
Year = list(inputId = "year", title = "Year(s)"),
Quarter = list(inputId = "quarter", title = "Quarter(s)"),
Created_Date = list(inputId = "created_date", title = "Created Date(s)")
)
),
# End of selectizeGroupUI
dataTableOutput("validated_data_summary"),
br(),
br(),
plotOutput("validated_graph_raw_data"),
br(),
br(),
plotOutput("validated_graph_percent_data") # End of tabPanel
) # End of tabBox
) # end of FluidRow
))
)))
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# Upload raw data file export
raw_data_upload <- reactive({
req(input$file)
readxl::read_excel(path = input$file$datapath)
})
validated_data_summary_filters <- callModule(
module = selectizeGroupServer,
id = "validated_data_summary_filters",
data = df,
vars = c("Year", "Quarter", "Created Date")
)
# Validated Data
output$validated_data_summary <- renderDT({
df <- raw_data_upload()
get_validated_summary_df(validated_data_summary_filters()) %>%
datatable(
class = 'cell-border stripe',
rownames = FALSE,
filter = 'top',
extensions = c('Select', 'SearchPanes', 'Buttons'),
options = list(
pageLength = 10,
lengthMenu = list(c(10, 25, 100, 500), c(10, 25, 100, 500)),
paging = T,
scrollX = TRUE,
dom = 'PBlfrtip',
buttons = c('csv', 'excel', 'colvis'),
columnDefs = list(
list(
searchPanes = list(show = FALSE),
targets = c(0:3)
),
list(className = 'dt-center', targets = "_all")
)
)
)
}, server = FALSE)
output$validated_graph_raw_data <- renderPlot({
example_function(validated_data_summary_filters())
})
output$validated_graph_percent_data <- renderPlot({
example_function(validated_data_summary_filters())
})
}
# Run the application
shinyApp(ui, server)
global.r
df <- data.frame(
`Created Date` = c("2022-11-22", "2022-08-09"),
`Protocol Name` = c("Protocol1", "Protocol2")
)
get_validated_summary_df <- function(df) {
modified_data <- df %>%
mutate(Quarter = quarters(as.Date(`Created Date`)),
Year = format(as.Date(`Created Date`, format = "%d/%m/%Y"), "%Y"))
return(modified_data)
}