0

我正在构建一个闪亮的应用程序,它有 2 个选项卡,侧边栏略有不同。对于第一个侧边栏,我想要一个具有数据集名称的 selectInput,并且默认选择所有这些名称(不是通过使用诸如添加“全部”选项之类的解决方法,而是从字面上选择所有选项)。

最终,我希望可用选项对用户的日期输入做出反应,但现在,我只想创建 renderUI 来填充我的选项。

但是,当我尝试时,出现以下错误:

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

我尝试查找其他答案,例如 5 年前的这个答案,但它对我的问题没有帮助。

我认为问题发生在这段代码中:

    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)))

但我也在这里包含了我的整个代码:

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)))
      
      
      
    })
    

    
  }
)


4

0 回答 0