0

I am building a shinyApp that has 2 tabs with slightly different sidebars. For the first sidebar, I want a selectInput that has the names of the dataset and for the default to select all of them (not by using a workaround like adding an "All" option, but literally selecting all the options).

Eventually, I'll want the available choices to be reactive to user's date input, but for now, I just want to create the renderUI to populate my options.

When I try though, I get the following error:

Error in match.arg(position) : 'arg' must be NULL or a character vector

I tried looking up other answers, like this answer from 5 years ago, but it didn't help me with my issue.

I think the issue is happening within this block of code:

    output$project_filter <- renderUI({ #or the issue is likely here
      shiny::req(input$file)
      shiny::req(input$upload)
      selectInput(inputId = "filter_by_project",
                  label = "Filter by Project",
                  choices = sort(unique(test$name)),
                  multiple = TRUE,
                  selected = sort(unique(test$name)))

But I've included my entire code here too:

library(shiny)
library(plotly)
library(shinyjs)
library(shinydashboard)
library(shinyWidgets) 
library(dplyr)
library(htmltools)

dates_notes_text <- HTML("Dates are filterable by month and year, not day (e.g., selecting 1 November 2021 or 25 November 2021 will yield the same result). <br><br>
                     To display only one month, have the start and end month be the same (e.g., both November 2021). <br><br>
                     Visualizations on display up to 12 consecutive month.")

test <- tibble(name = c("Justin", "Corey","Sibley"),
               april_2021 = c(10, 100, 101),
               may_2021 = c(1, 4, 7))

shinyApp(
  ui = fluidPage(
    tabsetPanel(
      tabPanel("Project View", fluid = TRUE,
               sidebarLayout(
                 sidebarPanel(
                              h4("Upload Utilization Report"),
                              fileInput("file", "Upload Tracker Data (.xlsx format only)",
                                        multiple = FALSE,
                                        accept = c(".xlsx")),
                              actionButton(inputId = "upload", 
                                           label = "Upload Data", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B"),
                              br(),
                              br(),
                              h4("Select Your Desired Filters"),
                              div(id = "inputs",
                                  dateRangeInput(
                                    inputId = "date_filter",
                                    label = "Filter by Month and Year",
                                    start = today(),
                                    end = (today() + 90),
                                    min = "2021-04",
                                    max = NULL,
                                    format = "yyyy-mm",
                                    startview = "month",
                                    weekstart = 0,
                                    language = "en",
                                    separator = " to ",
                                    width = NULL,
                                    autoclose = TRUE
                                  ),
                                  actionButton(inputId = "date_notes", 
                                               label = "Notes about Dates", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B"),
                                  br())),
                 h3("Include/Exclude Specific Projects"),
                 uiOutput("project_filter"), #I think the issue is either here or in server (see note)
                 mainPanel(
                 )
               )
      ),
      tabPanel("Resource View", fluid = TRUE,
               sidebarLayout(
                 sidebarPanel( 
                              h4("Upload Utilization Report"),
                              fileInput("file", "Upload Tracker Data (.xlsx format only)",
                                        multiple = FALSE,
                                        accept = c(".xlsx")),
                              actionButton(inputId = "upload", 
                                           label = "Upload Data", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B"),
                              br(),
                              br(),
                              h4("Select Your Desired Filters"),
                              div(id = "inputs",
                                  dateRangeInput(
                                    inputId = "date_filter",
                                    label = "Filter by Month",
                                    start = today(),
                                    end = (today() + 90),
                                    min = "2020-04",
                                    max = NULL,
                                    format = "yyyy-mm",
                                    startview = "month",
                                    weekstart = 0,
                                    language = "en",
                                    separator = " to ",
                                    width = NULL,
                                    autoclose = TRUE
                                  ),
                                  actionButton(inputId = "date_notes", 
                                               label = "Notes about Dates", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B"),
                                  br())),
                 mainPanel(fluidRow(
                 )
                 )
               )
      )
    )
  ), 
  server = function(input, output) {
    
    observeEvent(input$date_notes, {
      showModal(modalDialog(dates_notes_text, title = "Information about Selecting Dates"))
    })
    
    output$project_filter <- renderUI({ #or the issue is likely here
      shiny::req(input$file)
      shiny::req(input$upload)
      selectInput(inputId = "filter_by_project",
                  label = "Filter by Project",
                  choices = sort(unique(test$name)),
                  multiple = TRUE,
                  selected = sort(unique(test$name)))
      
      
      
    })
    

    
  }
)


J.Sabree
  • 2,280
  • 19
  • 48
  • The question you linked ([39967867](https://stackoverflow.com/questions/39967867/shiny-error-in-match-argposition-arg-must-be-null-or-a-character-vector)) already contains the answer. You are calling `sidebarLayout()` with too many arguments. This error has nothing to do with the server and can be reproduced with an "empty" server argument to `shinyApp()` – Gregor de Cillia Jul 29 '21 at 22:45
  • @GregordeCillia , thanks I saw that but it doesn’t help explain how to fix it. The asker in that post explicitly asked what to do if they had 2 side bars but the responder didn’t know. How can I update my code here for it to work or to accomplish something similar? – J.Sabree Jul 29 '21 at 23:03
  • 1
    You need to include `h3("Include...")` and `uiOutput("project_filter")` in either `sidebarPanel()` or `mainPanel()`. Both tabs will have their own sidebarPanel. – YBS Jul 30 '21 at 02:11

0 Answers0