How to make select() and filter() functions work together in the server in shiny?

I am trying to create an app where the user would be able to select desired columns and then be able to filter the columns according to the desired results. The output will be a table. I have tried adjusting my code in the server multiple times and on each occasion I run in to an error where it either does not recognise an input. However, I am able to use either the one or the other.

Here is my code at the moment - in this code only the "select columns" are functional:

ui <- fluidPage(theme = bslib::bs_theme(bootswatch = "sandstone"),
                titlePanel("Biodiversity Monitoring Database"),
                "Biodiversity monitoring projects and research conducted in South Africa and its   territories",
                br(), 
                br(),
                
                br(),
                br(),
                sidebarLayout(
                  sidebarPanel("Select desired columns to generate table.", 
                               br(),
                               br(),
                               em("Please note that the columns will show duplicate data as some entries have occurred in multiple provinces, realms and/or has multiple EBVs (Essential Biodiversity Variables)"),
                               br(),
                               br(),
                               #selectInput will create a dropdown list
                               selectInput("SelectColumns", "Select Column", choices = names(bmd), multiple = T),
                               br(),
                               br(),
                               strong("Filter lists in Biodiversity Monitoring Table"),
                               
                               
                               selectInput(inputId = "taxon", #the input field from your dataset
                                           label = "Taxon", # you can label as you like
                                           choices = sort(unique(bmd$taxon)), 
                                           multiple = TRUE), 
                               selectInput(inputId = "realm",
                                           label = "Realm",
                                           choices = sort(unique(bmd$realm)),
                                           multiple = TRUE),
                               selectInput(inputId = "ebv",
                                           label = "Essential Biodiversity Viarables",
                                           choices = sort(unique(bmd$ebv)),
                                           multiple = TRUE),
                               selectInput(inputId = "reason_for_monitoring_this_species_genus",
                                           label = "Reason for monitoring",
                                           choices = sort(unique(bmd$reason_for_monitoring_this_species_genus)),
                                           multiple = TRUE),
                  ),
                  
                  
                  
                mainPanel(strong("Biodiversity Monitoring Table"), #title/ description of the mainPanel which will show opposite the sidePanel
                            br(),
              
                            br(),
                          DTOutput("biodiversityTable"),
                          downloadButton("download", "Download .pdf")) #this function tells R to create a table - you get different types of outputs eg. graphs
                )
)```

server <- function(input, output, session){
  output$biodiversityTable <- renderDT({
    bmd %>% 
      

    
      select(!!! rlang::syms(input$SelectColumns)) },
filter = "top",
rownames = FALSE)
  
  reactive({
    bmd %>%
  
  filter(taxon == input$taxon, 
         realm == input$realm,
         ebv == input$ebv,
         reason_for_monitoring_this_species_genus == input$reason_for_monitoring_this_species_genus) 
  
    
  })
  

  output$download <-downloadHandler(
    filename = function() {
      paste0(input$bmd, ".pdf")
    },
    content = function(file) {
      vroom::vroom_write(data(), file)
    }
  )
    
}
The above server code does not give me any error messages now but the filter functions does not generate in the app.

Please note: I am quite new to shiny so my code might not be the best.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.