1

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)
}
JaW
  • 33
  • 5
  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). As is we can't run your code as we neither have your script `validated_data_transformations.R` nor do we have any example data. – stefan Feb 28 '23 at 22:24
  • Hi, yes you're correct - sorry I was scrubbing the code I have of company information. I've added a really basic dataframe and transformation function example. Basically I was trying to utilize the selectizeGroupUI to be able to filter based on Year, Quarter, and Created Date, and have that filtered dataframe be passed on to different functions or plots. – JaW Feb 28 '23 at 22:31

1 Answers1

0

I answered my own question. I had incorrectly tied together the Server elements of the selectizeGroupUI with the UI elements. Once those were tied together, and I passed the reactive object (raw_data_upload()) straight to callModule, it worked as expected.

JaW
  • 33
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 01 '23 at 09:15